package com.sxfq.loansupermarket.backsystem.modular.tcCenter.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sxfq.loansupermarket.backsystem.common.constant.factory.PageFactory;
import com.sxfq.loansupermarket.backsystem.common.controller.BaseController;
import com.sxfq.loansupermarket.backsystem.common.exception.BizExceptionEnum;
import com.sxfq.loansupermarket.backsystem.common.exception.BussinessException;
import com.sxfq.loansupermarket.backsystem.common.persistence.model.Dept;
import com.sxfq.loansupermarket.backsystem.common.persistence.model.Role;
import com.sxfq.loansupermarket.backsystem.core.log.LogManager;
import com.sxfq.loansupermarket.backsystem.core.log.factory.LogTaskFactory;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.support.DateTimeKit;
import com.sxfq.loansupermarket.backsystem.core.support.HttpKit;
import com.sxfq.loansupermarket.backsystem.core.util.CommUtils;
import com.sxfq.loansupermarket.backsystem.core.util.StringUtil;
import com.sxfq.loansupermarket.backsystem.core.util.ToolUtil;
import com.sxfq.loansupermarket.backsystem.modular.arrival.entity.CustomerInfo;
import com.sxfq.loansupermarket.backsystem.modular.arrival.entity.SearchCustomerInfo;
import com.sxfq.loansupermarket.backsystem.modular.arrival.service.ICustomerService;
import com.sxfq.loansupermarket.backsystem.modular.base.SqlMapper;
import com.sxfq.loansupermarket.backsystem.modular.basicData.entity.PayServiceInfo;
import com.sxfq.loansupermarket.backsystem.modular.marketing.entity.ReservationsInfo;
import com.sxfq.loansupermarket.backsystem.modular.marketing.service.IReservationsService;
import com.sxfq.loansupermarket.backsystem.modular.refunds.entity.RechargeInfo;
import com.sxfq.loansupermarket.backsystem.modular.refunds.entity.RefundInfo;
import com.sxfq.loansupermarket.backsystem.modular.tcCenter.entity.*;
import com.sxfq.loansupermarket.backsystem.modular.tcCenter.service.IConsultantService;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.BufferedOutputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 预约客户信息
 *
 * @author py
 * @Date 2018年4月19日23:15:54
 */
@Controller
@RequestMapping("/consultant")
public class ConsultantController extends BaseController {
    @Autowired
    IConsultantService service;

    @Autowired
    ICustomerService customerService;

    @Autowired
    IConsultantService consultantService;

    @Autowired
    IReservationsService reservationsService;

    @Autowired
    private SqlMapper sqlMapper;

    private String PREFIX = "/tcCenter/consultant/";

    /**
     * 跳转到TC看诊
     */
    @RequestMapping("")
    public String consultant(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        return PREFIX + "/consultant_examination.html";
    }

    /**
     * 跳转到预约回访
     */
    @RequestMapping("/reserve")
    public String reserve(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        return PREFIX + "consultant_reserve.html";
    }

    /**
     * 跳转到回访记录
     */
    @RequestMapping("/record")
    public String consultantRecord(Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        return PREFIX + "/consultant_record.html";
    }

    /**
     * 跳转到预约客户管理详情页面
     */
    @RequestMapping(value = "/consultant_diagnosis/{consultantId}")
    public String diagnosis(@PathVariable String consultantId, Model model) {
        if (ToolUtil.isEmpty(consultantId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        ConsultantInfo consultantInfo = this.service.selectOneById(consultantId);
        model.addAttribute("consultantInfo", consultantInfo);
        return PREFIX + "consultant_diagnosis.html";
    }

    @RequestMapping(value = "/to_addVisited/{reservationsId}")
    public String toAddVisited(@PathVariable String reservationsId, Model model) {
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "addVisited.html";
    }

    /**
     * 分配医生
     *
     * @param customerId
     * @param model
     * @return
     */
    @RequestMapping(value = "/to_distributiveDoctor/{customerId}")
    public String toDistributiveDoctor(@PathVariable String customerId, Model model) {
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("customerId", customerId);
        return PREFIX + "distributive_doctor.html";
    }

    /**
     * 分配护士
     *
     * @param customerId
     * @param model
     * @return
     */
    @RequestMapping(value = "/to_distributiveNurse/{customerId}")
    public String toDistributiveNurse(@PathVariable String customerId, Model model) {
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("customerId", customerId);
        return PREFIX + "distributive_nurse.html";
    }

    /**
     * 分配转诊人
     *
     * @param customerId
     * @param model
     * @return
     */
    @RequestMapping(value = "/to_distributiveReferrer/{customerId}")
    public String to_distributiveReferrer(@PathVariable String customerId, Model model) {
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("customerId", customerId);
        return PREFIX + "distributive_referrer.html";
    }

    /**
     * 跳转到修改欠费
     *
     * @param ia
     * @param model
     * @return
     */
    @RequestMapping(value = "/to_accountArrears/{ia}")
    public String to_accountArrears(@PathVariable String ia, Model model) {
        String reservationsId = ia.split(",")[0];
        String accountArrears = ia.split(",")[1];
        if (ToolUtil.isEmpty(ia)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("accountArrears", accountArrears);
        return PREFIX + "customer_accountArrears.html";
    }

    /**
     * 修改欠费
     */
    @RequestMapping(value = "/update_accountArrears", method = RequestMethod.POST)
    @ResponseBody
    public int update_accountArrears(String reservationsId, String accountArrears, Model model) {
        String sql = "update " + this.getTableName() + " set account_arrears='" + accountArrears + "' where reservations_id='" + reservationsId + "'";
        return sqlMapper.update(sql);
    }

    /**
     * 跳转到修改缴费
     *
     * @param ia
     * @param model
     * @return
     */
    @RequestMapping(value = "/to_actualAccountBalance/{ia}")
    public String to_actualAccountBalance(@PathVariable String ia, Model model) {
        String reservationsId = ia.split(",")[0];
        String actualAccountBalance = ia.split(",")[1];
        if (ToolUtil.isEmpty(ia)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("actualAccountBalance", actualAccountBalance);
        return PREFIX + "customer_actualAccountBalance.html";
    }

    /**
     * 修改缴费
     */
    @RequestMapping(value = "/update_actualAccountBalance", method = RequestMethod.POST)
    @ResponseBody
    public int update_actualAccountBalance(String reservationsId, String actualAccountBalance, Model model) {
        String sql = "update " + this.getTableName() + " set actual_account_balance='" + actualAccountBalance + "' where reservations_id='" + reservationsId + "'";
        return sqlMapper.update(sql);
    }

    /**
     * 开单t跳转打印
     *
     * @param customerId
     * @param model
     * @return
     */
    @RequestMapping(value = "/singlePrint/{customerId}")
    public String singlePrint(@PathVariable String customerId, Model model) {
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }

        String tableName1 = tableHead + "deal_info";
        //查询当前修改 记录的客户对应所有的临时开单记录给前端
        String sql2 = "select * from " + tableName1 + " t1 " +
                " left join pay_service_info t2 on t1.pay_service_id=t2.id where " +
                "  t1.customer_id='" + customerId + "' and t1.operation_time=(select  operation_time  from " + tableName1 + " t1" +
                " where t1.customer_id='" + customerId + "'  order by operation_time desc limit 0,1)";
        List<PayServiceInfo> payServiceInfo = sqlMapper.selectList(sql2, PayServiceInfo.class);
        String sql1 = "select   sum(t1.folding_pay)  as totleFoldingPay,t2.customer_name as customerName,t2.field_tc as fieldTc, " +
                "GROUP_CONCAT( distinct (t1.doctor)) as doctor, " +
                "left(t1.operation_time,10) as operationTime , t1.remarks as remarks from " + tableName1 + " t1   " +
                "left join " + this.getTableName() + " t2 on t1.customer_id=t2.id   " +
                " where t1.customer_id='" + customerId + "' and t1.operation_time=(select  operation_time  from " + tableName1 + " t1" +
                " where t1.customer_id='" + customerId + "'  order by operation_time desc limit 0,1)" +
                " group by t1.customer_id";
        PayServiceInfo payService = sqlMapper.selectOne(sql1, PayServiceInfo.class);

        model.addAttribute("payService", payService);
        model.addAttribute("payServiceInfo", payServiceInfo);
        return PREFIX + "distributive_singlePrint.html";
    }

    /**
     * 开单记录确认打印
     *
     * @param
     * @param
     * @return
     */
    @RequestMapping(value = "/singlePrintt/{ids}")
    public String singlePrintt(@PathVariable String ids, Model model) {
        String customerId = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String operationTime = ids.split(",")[2];
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(operationTime)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }

        String tableName1 = tableHead + "deal_info";
        //查询当前修改 记录的客户对应所有的临时开单记录给前端
        String sql2 = "select * from " + tableName1 + " t1 " +
                " left join pay_service_info t2 on t1.pay_service_id=t2.id where " +
                "  t1.customer_id='" + customerId + "' and t1.operation_time='" + operationTime + "'";
        List<PayServiceInfo> payServiceInfo = sqlMapper.selectList(sql2, PayServiceInfo.class);
        String sql1 = "select   sum(t1.folding_pay)  as totleFoldingPay,t2.customer_name as customerName,t2.field_tc as fieldTc, " +
                "GROUP_CONCAT( distinct (t1.doctor)) as doctor, " +
                "left(t1.operation_time,10) as operationTime , t1.remarks as remarks from " + tableName1 + " t1   " +
                "left join " + this.getTableName() + " t2 on t1.customer_id=t2.id   " +
                " where t1.customer_id='" + customerId + "' and t1.operation_time='" + operationTime + "' group by t1.customer_id";
        PayServiceInfo payService = sqlMapper.selectOne(sql1, PayServiceInfo.class);

        model.addAttribute("payService", payService);
        model.addAttribute("payServiceInfo", payServiceInfo);
        return PREFIX + "distributive_singlePrint.html";
    }

    /**
     * 修改项目
     *
     * @param
     * @param
     * @return
     */
    @RequestMapping(value = "/updateDeal/{ids}")
    public String updateDeal(@PathVariable String ids, Model model) {
        String id = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String operationTime = ids.split(",")[2];
        List<PayServiceInfo> payServiceInfoList = service.getPayServiceInfoList();
        //项目
        model.addAttribute("payServiceInfoList", payServiceInfoList);
        model.addAttribute("id", id);
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("operationTime", operationTime);
        return PREFIX + "update_bill.html";
    }

    /**
     * 修改渠道
     *
     * @param model
     * @return
     */
    @RequestMapping("/cusupdate_channel/{id}")
    public String updateChannel(@PathVariable String id, Model model) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        CustomerInfo customerInfo = customerService.selectOneById(id);
        model.addAttribute("customerInfo", customerInfo);
        model.addAttribute("customerId", id);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        return PREFIX + "update_channel.html";
    }


    @RequestMapping(value = "/to_arrearsRemarks/{cras}")
    public String toArrearsRemarks(@PathVariable String cras, Model model) {
        String customerId = cras.split(",")[0];
        String reservationsId = cras.split(",")[1];
        String arrears = cras.split(",")[2];
        String serviceActualPay = cras.split(",")[3];
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        ConsultantInfo consultantInfo = this.service.selectOneById(customerId);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("customerId", customerId);
        model.addAttribute("arrears", arrears);
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("serviceActualPay", serviceActualPay);
        return PREFIX + "arrears_remarks.html";
    }

    @RequestMapping(value = "/to_updateDoctor/{customerId}")
    public String toUpdateDoctor(@PathVariable String customerId, Model model) {
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        model.addAttribute("customerId", customerId);
        return PREFIX + "update_doctor.html";
    }

    @RequestMapping(value = "/updateDoctor", method = RequestMethod.POST)
    @ResponseBody
    public int getTotleMoney(String doctor, String customerId) throws Exception {
        if (ToolUtil.isEmpty(doctor)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName = tableHead + "customer_info";
        String sql = " update " + tableName + " t  set t.doctor='" + doctor + "' where t.id='" + customerId + "'";
        String sq11 = "INSERT INTO `distributive_doctor_log` ( `customer_id`, `tc_name`, `distributive_doctor`, `distributive_time`) VALUES " +
                " ( '" + customerId + "', '" + ShiroKit.getUser().getAccount() + "', '" + doctor + "', '" + DateTimeKit.now() + "');";
        sqlMapper.insert(sq11);
        return sqlMapper.update(sql);
    }

    @RequestMapping(value = "/getDealInfo", method = RequestMethod.POST)
    @ResponseBody
    public List<PayServiceInfo> getDealInfo(String reservationsId, String operationTime) throws Exception {
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(operationTime)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName = tableHead + "deal_info";
        String sql = "select * from " + tableName + " t left join pay_service_info t1 on t.pay_service_id=t1.id where t.reservations_id='" + reservationsId + "' and t.operation_time='" + operationTime + "';";
        List<PayServiceInfo> payServiceList = sqlMapper.selectList(sql, PayServiceInfo.class);
        return payServiceList;
    }

    //分配医生
    @RequestMapping(value = "/getDoctor", method = RequestMethod.GET)
    @ResponseBody
    public List<ConsultantInfo> getDoctor() throws Exception {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String sql = " select a.id as id,a.account as doctor from user a left join  dept b on a.deptid=b.id left join role c on find_in_set(c.id,a.roleid) > 0 " +
                " where b.abbreviation='" + tableHead + "' and c.name='医生'";
        List<ConsultantInfo> list = sqlMapper.selectList(sql, ConsultantInfo.class);
        return list;
    }

    //分配护士
    @RequestMapping(value = "/getNurse", method = RequestMethod.GET)
    @ResponseBody
    public List<ConsultantInfo> getArchivings() throws Exception {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String sql = " select a.id as id,a.name as nurse from user a left join  dept b on a.deptid=b.id left join role c on a.roleid=c.id  where b.abbreviation='" + tableHead + "' and c.name='护士' or b.abbreviation='" + tableHead + "' and c.name='医生' \n" +
                " or b.abbreviation='" + tableHead + "' and c.name='洁牙师' ";
        List<ConsultantInfo> list = sqlMapper.selectList(sql, ConsultantInfo.class);
        return list;
    }

    /**
     * 预约客户管理列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object testrInfoList(SearchConsultantInfo info, HttpServletRequest request) {
        Page<ConsultantInfo> page = new PageFactory<ConsultantInfo>().defaultPage();
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        try {
            info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
            info.setLimitIndex(page.getSize());
            page.setCurrent(0);
            List<ConsultantInfo> list = service.selectPageListByQueryGetMap(page, info);
            if (list.size() == 0) {
                info.setStartIndex(0);
                list = service.selectPageListByQueryGetMap(page, info);
            }
            page.setTotal(service.getQueryPagesCount(page, info));
            page.setRecords(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }

    /**
     * 预约客户管理列表
     */
    @RequestMapping("/resList")
    @ResponseBody
    public Object resInfoList(SearchConsultantInfo info, HttpServletRequest request) {
        Page<ConsultantInfo> page = new PageFactory<ConsultantInfo>().defaultPage();
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        try {
            info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
            info.setLimitIndex(page.getSize());
            page.setCurrent(0);
            List<ConsultantInfo> list = service.selectPageListByQuery(page, info);
            if (list.size() == 0) {
                info.setStartIndex(0);
                list = service.selectPageListByQuery(page, info);
            }
            page.setTotal(service.getQueryPagesCount(page, info));
            page.setRecords(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return super.packForBT(page);
    }

    /**
     * 修改考题
     */
    @RequestMapping(value = "/diagnosis")
    @ResponseBody
    public int update(@Valid ConsultantInfo info, BindingResult result) throws Exception {
        if (result.hasErrors()) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        service.updateDiagnosisStatus(info.getId());
        return service.insert(info);
    }

    /**
     *
     */
    @RequestMapping(value = "/consultant_update/{customerId}")
    @ResponseBody
    public List<ConsultantInfo> consultantUpdate(@PathVariable String customerId, Model model) throws Exception {
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        return service.selectDiagnosisById(customerId);
    }

    @RequestMapping(value = "/isOperations/{customerId}")
    public String isOperations(@PathVariable String customerId, Model model) throws Exception {
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        List<PayServiceInfo> payServiceInfoList = service.getPayServiceInfoList();
        String sql = "select t2.id as customerId,t2.customer_phone as customerPhone,t2.reservations_id as reservationsId,t2.customer_name as customerName,t2.medical_record_number as medicalRecordNumber" +
                ",(\n" +
                "        CASE t2.customer_sex\n" +
                "        WHEN 1 THEN\n" +
                "            '男'\n" +
                "        WHEN 2 THEN\n" +
                "            '女'\n" +
                "        ELSE\n" +
                "            '未知'\n" +
                "        END\n" +
                "    ) as sex,t2.customer_age as customerAge ,t2.field_tc as fieldTc" +
                " from " + this.getTableName() + " t2 where id='" + customerId + "'";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql, ConsultantInfo.class);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("payServiceInfoList", payServiceInfoList);
        ShiroKit.setSessionAttr("customerId", customerId);
        CustomerInfo customerInfo = customerService.selectOneById(customerId);
        ShiroKit.setSessionAttr("reservationsId", customerInfo.getReservationsId());
        String sql1 = "delete from open_bill_info where tc_name='" + ShiroKit.getUser().getAccount() + "' and customer_id='" + ShiroKit.getSessionAttr("customerId") + "'";
        sqlMapper.delete(sql1);
        return PREFIX + "open_bills.html";
    }

    @RequestMapping(value = "/isOperation/{customerId}")
    public String isOperation(@PathVariable String customerId, Model model) throws Exception {
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        List<PayServiceInfo> payServiceInfoList = service.getPayServiceInfoList();
        String sql = "select t2.id as customerId,t2.customer_phone as customerPhone,t2.reservations_id as reservationsId,t2.customer_name as customerName,t2.medical_record_number as medicalRecordNumber" +
                ",if(t2.customer_sex=1,'男','女') as sex,t2.customer_age as customerAge ,t2.field_tc as fieldTc" +
                " from " + this.getTableName() + " t2 where id='" + customerId + "'";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql, ConsultantInfo.class);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("payServiceInfoList", payServiceInfoList);
        ShiroKit.setSessionAttr("customerId", customerId);
        CustomerInfo customerInfo = customerService.selectOneById(customerId);
        ShiroKit.setSessionAttr("reservationsId", customerInfo.getReservationsId());
        String sql1 = "delete from open_bill_info where tc_name='" + ShiroKit.getUser().getAccount() + "' and customer_id='" + ShiroKit.getSessionAttr("customerId") + "'";
        sqlMapper.delete(sql1);
        return PREFIX + "open_bill.html";
    }

    @RequestMapping(value = "/isNoOperation/{customerId}")
    public String isNoOperation(@PathVariable String customerId, Model model) throws Exception {
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        List<PayServiceInfo> payServiceInfoList = service.getPayServiceInfoList();
        String sql = "select t2.id as customerId,t2.customer_phone as customerPhone,t2.reservations_id as reservationsId,t2.customer_name as customerName,t2.medical_record_number as medicalRecordNumber" +
                ",(\n" +
                "        CASE t2.customer_sex\n" +
                "        WHEN 1 THEN\n" +
                "            '男'\n" +
                "        WHEN 2 THEN\n" +
                "            '女'\n" +
                "        ELSE\n" +
                "            '未知'\n" +
                "        END\n" +
                "    ) as sex,t2.customer_age as customerAge ,t2.field_tc as tcName" +
                " from " + this.getTableName() + " t2 where id='" + customerId + "'";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql, ConsultantInfo.class);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("payServiceInfoList", payServiceInfoList);
        ShiroKit.setSessionAttr("customerId", customerId);
        CustomerInfo customerInfo = customerService.selectOneById(customerId);
        ShiroKit.setSessionAttr("reservationsId", customerInfo.getReservationsId());
        String sql1 = "delete from open_bill_info where tc_name='" + ShiroKit.getUser().getAccount() + "' and customer_id='" + ShiroKit.getSessionAttr("customerId") + "'";
        sqlMapper.delete(sql1);
        return PREFIX + "is_noOperation.html";
    }

    @RequestMapping(value = "/to_revisitOperation/{reservationsId}")
    public String toRevisitOperation(@PathVariable String reservationsId, Model model) throws Exception {
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String sql = "select t2.id as customerId,t2.reservations_id as reservationsId,t2.customer_name as customerName,t2.medical_record_number as medicalRecordNumber" +
                ",t2.customer_sex as customerSex,t2.customer_age as customerAge ,t2.field_tc as tcName" +
                " from " + this.getTableName() + " t2 where reservations_id='" + reservationsId + "' order by t2.arrival_time desc limit 0,1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql, ConsultantInfo.class);
        String sql1 = "select * from reservations_info where id='" + reservationsId + "' limit 0,1";
        ReservationsInfo reservationsInfo = sqlMapper.selectOne(sql1, ReservationsInfo.class);
        List<AddVisitedInfo> revisitRecordList = service.getRevisitRecordList(reservationsId);
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("revisitRecordList", revisitRecordList);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("reservationsInfo", reservationsInfo);
        model.addAttribute("reservations", ShiroKit.getUser().getAccount());
        return PREFIX + "is_revisit.html";
    }

    @RequestMapping(value = "/to_payMent/{id}")
    public String to_payMent(@PathVariable String id, Model model) throws Exception {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String tableName1 = tableHead + "deal_info";
        String selectSql = "select  * from " + tableName1 + " where id='" + id + "'";
        PaymentInfo paymentInfos = sqlMapper.selectOne(selectSql, PaymentInfo.class);
        String sql = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id " +
                " where t1.deal_status!='未成交' and  t1.operation_time='" + paymentInfos.getOperationTime() + "' and t1.reservations_id='" + paymentInfos.getReservationsId() + "'";
        List<PayServiceInfo> openBillList = sqlMapper.selectList(sql, PayServiceInfo.class);
        Double totleReceivable = 0.00;
        Double totleFoldingPay = 0.00;
        Double totleServiceActualPay = 0.00;
        for (PayServiceInfo info : openBillList) {
            if (info.getPayServiceNum() != null) {
                totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
            }
            if (info.getFoldingPay() != null) {
                totleFoldingPay += info.getFoldingPay();
            }
            if (info.getServiceActualPay() != null) {
                totleServiceActualPay += info.getServiceActualPay();
            }
            info.setTotleReceivable(totleReceivable);
            info.setTotleFoldingPay(totleFoldingPay);
        }
        String sql1 = "select t2.id as customerId,t2.reservations_id as reservationsId,t2.customer_name as customerName,t2.medical_record_number as medicalRecordNumber" +
                ",t2.customer_sex as customerSex,t2.customer_age as customerAge ,t2.field_tc as tcName" +
                " from " + this.getTableName() + " t2 where reservations_id='" + paymentInfos.getReservationsId() + "' order by t2.arrival_time desc limit 0,1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("customerId", paymentInfos.getCustomerId());
        model.addAttribute("reservationsId", paymentInfos.getReservationsId());
        model.addAttribute("operationTime", paymentInfos.getOperationTime());
        model.addAttribute("openBillList", openBillList);
        model.addAttribute("totleFoldingPay", totleFoldingPay);
        return PREFIX + "payment.html";
    }

    @RequestMapping(value = "/to_supplement/{ai}")
    public String to_supplement(@PathVariable String ai, Model model) throws Exception {
        String arrears = ai.split(",")[0];
        String id = ai.split(",")[1];
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String tableName1 = tableHead + "deal_info";
        String selectsql = "select * from " + tableName1 + " where id='" + id + "'";
        RechargeInfo rechargeInfo1 = sqlMapper.selectOne(selectsql, RechargeInfo.class);
        String operationTime = rechargeInfo1.getOperationTime();
        String reservationsId = rechargeInfo1.getReservationsId();
        String customerId = rechargeInfo1.getCustomerId();
        String sql = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.folding_pay as foldingPay,t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks,t1.arrears as arrears," +
                " t2.pay_service_name as payServiceName,t1.pay_service_id as payServiceId, t2.pay_service_price_one as payServicePriceOne,t2.pay_service_price_two as payServicePriceTwo from " + tableName1 + " t1 left join \n" +
                " pay_service_info t2 on t1.pay_service_id=t2.id where operation_time='" + operationTime + "' and reservations_id='" + reservationsId + "'";
        List<PayServiceInfo> openBillList = sqlMapper.selectList(sql, PayServiceInfo.class);
        Double totleReceivable = 0.00;
        Double totleFoldingPay = 0.00;
        Double totleServiceActualPay = 0.00;
        Double accountArrears = 0.00;
        for (PayServiceInfo info : openBillList) {
            if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                if (info.getPayServiceNum() != null) {
                    totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
                }
                if (info.getFoldingPay() != null) {
                    totleFoldingPay += info.getFoldingPay();
                }
                if (info.getServiceActualPay() != null) {
                    totleServiceActualPay += info.getServiceActualPay();
                }
                if (info.getArrears() != null) {
                    accountArrears += info.getArrears();
                }
                info.setTotleReceivable(totleReceivable);
                info.setTotleFoldingPay(totleFoldingPay);
                info.setTotleServiceActualPay(totleServiceActualPay);
                info.setAccountArrears(accountArrears);
            }
        }
        String sql1 = "select t2.id as customerId,t2.reservations_id as reservationsId,t2.customer_name as customerName,t2.medical_record_number as medicalRecordNumber" +
                ",t2.customer_sex as customerSex,t2.customer_age as customerAge ,t2.field_tc as fieldTc" +
                " from " + this.getTableName() + " t2 where reservations_id='" + reservationsId + "' order by t2.arrival_time desc limit 0,1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("customerId", customerId);
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("operationTime", operationTime);
        model.addAttribute("totleFoldingPay", totleFoldingPay);
        model.addAttribute("accountArrears", arrears);
        return PREFIX + "supplement.html";
    }

    /**
     * 单个项目补欠款
     *
     * @param ai
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/payKuan/{ai}")
    public String payKuan(@PathVariable String ai, Model model) throws Exception {
        String customerId = ai.split(",")[0];
        String reservationsId = ai.split(",")[1];
        String operationTime = ai.split(",")[2];
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String tableName1 = tableHead + "deal_info";
        String sql = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t1.get_time as getTime from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id " +
                " where t1.reservations_id='" + reservationsId + "' and  t1.operation_time = '" + operationTime + "'and pay_service_id is not null  group by  operationTime order by operationTime desc";
        List<PayServiceInfo> payServiceInfoList = sqlMapper.selectList(sql, PayServiceInfo.class);
        String sql1 = "select t2.customer_name as customerName,t2.reservations_id as reservationsId,t2.medical_record_number as medicalRecordNumber," +
                "  (CASE t2.customer_sex  " +
                "  WHEN 1 THEN  " +
                "  '男'  " +
                "  WHEN 2 THEN  " +
                "  '女'  " +
                "  ELSE  " +
                "  '未知'  " +
                "  END  " +
                " ) as sex ,t2.customer_age as customerAge,t2.customer_phone as customerPhone ,t2.field_tc as fieldTc" +
                " from " + this.getTableName() + " t2 where id='" + customerId + "'";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        String getTime = "";
        Double totleReceivable = 0.00;
        Double totleFoldingPay = 0.00;
        Double totleServiceActualPay = 0.00;
        Double accountArrears = 0.00;
        for (PayServiceInfo info : payServiceInfoList) {
            if (info != null) {
                if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                    if (info.getPayServiceNum() != null) {
                        totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
                    }
                    if (info.getFoldingPay() != null) {
                        totleFoldingPay += info.getFoldingPay();
                    }
                    if (info.getServiceActualPay() != null) {
                        totleServiceActualPay += info.getServiceActualPay();
                    }
                    if (info.getArrears() != null) {
                        accountArrears += info.getArrears();
                    }
                    info.setTotleReceivable(totleReceivable);
                    info.setTotleFoldingPay(totleFoldingPay);
                    info.setTotleServiceActualPay(totleServiceActualPay);
                    info.setAccountArrears(accountArrears);
                }
                getTime = info.getGetTime();
            }
        }
        model.addAttribute("payServiceInfoList", payServiceInfoList);
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("customerId", customerId);
        model.addAttribute("getTime", getTime);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("operationTime", operationTime);

        return PREFIX + "buqiankuan.html";
    }

    /**
     * 单个项目补欠款
     *
     * @param ai
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/payKuans/{ai}")
    public String payKuans(@PathVariable String ai, Model model) throws Exception {
        String customerId = ai.split(",")[0];
        String reservationsId = ai.split(",")[1];
        String operationTime = ai.split(",")[2];
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String tableName1 = tableHead + "deal_info";
        String sql = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t1.get_time as getTime from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id " +
                " where t1.reservations_id='" + reservationsId + "' and  t1.operation_time = '" + operationTime + "'and pay_service_id is not null  group by  operationTime order by operationTime desc";
        List<PayServiceInfo> payServiceInfoList = sqlMapper.selectList(sql, PayServiceInfo.class);
        String sql1 = "select t2.customer_name as customerName,t2.reservations_id as reservationsId,t2.medical_record_number as medicalRecordNumber," +
                "  (CASE t2.customer_sex  " +
                "  WHEN 1 THEN  " +
                "  '男'  " +
                "  WHEN 2 THEN  " +
                "  '女'  " +
                "  ELSE  " +
                "  '未知'  " +
                "  END  " +
                " ) as sex ,t2.customer_age as customerAge,t2.customer_phone as customerPhone ,t2.field_tc as fieldTc" +
                " from " + this.getTableName() + " t2 where id='" + customerId + "'";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        String getTime = "";
        Double totleReceivable = 0.00;
        Double totleFoldingPay = 0.00;
        Double totleServiceActualPay = 0.00;
        Double accountArrears = 0.00;
        for (PayServiceInfo info : payServiceInfoList) {
            if (info != null) {
                if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                    if (info.getPayServiceNum() != null) {
                        totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
                    }
                    if (info.getFoldingPay() != null) {
                        totleFoldingPay += info.getFoldingPay();
                    }
                    if (info.getServiceActualPay() != null) {
                        totleServiceActualPay += info.getServiceActualPay();
                    }
                    if (info.getArrears() != null) {
                        accountArrears += info.getArrears();
                    }
                    info.setTotleReceivable(totleReceivable);
                    info.setTotleFoldingPay(totleFoldingPay);
                    info.setTotleServiceActualPay(totleServiceActualPay);
                    info.setAccountArrears(accountArrears);
                }
                getTime = info.getGetTime();
            }
        }
        model.addAttribute("payServiceInfoList", payServiceInfoList);
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("customerId", customerId);
        model.addAttribute("getTime", getTime);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("operationTime", operationTime);

        return PREFIX + "buqiankuans.html";
    }

    /**
     * 退款操作 refundMoney
     */
    @RequestMapping(value = "/refundMoney/{parpams}")
    public String refundMoney(@PathVariable String parpams, Model model) throws Exception {
        String customerId = parpams.split(",")[0];
        String reservationsId = parpams.split(",")[1];
        String operationTime = parpams.split(",")[2];
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String tableName1 = tableHead + "deal_info";
        String sql = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t1.get_time as getTime,t1.check_status as checkStatus from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id " +
                " where t1.reservations_id='" + reservationsId + "' and  t1.operation_time = '" + operationTime + "'and pay_service_id is not null  group by  operationTime order by operationTime desc";
        List<PayServiceInfo> payServiceInfoList = sqlMapper.selectList(sql, PayServiceInfo.class);
        String sql1 = "select t2.customer_name as customerName,t2.reservations_id as reservationsId,t2.medical_record_number as medicalRecordNumber," +
                "  (CASE t2.customer_sex  " +
                "  WHEN 1 THEN  " +
                "  '男'  " +
                "  WHEN 2 THEN  " +
                "  '女'  " +
                "  ELSE  " +
                "  '未知'  " +
                "  END  " +
                " ) as sex ,t2.customer_age as customerAge,t2.customer_phone as customerPhone ,t2.field_tc as fieldTc" +
                " from " + this.getTableName() + " t2 where id='" + customerId + "'";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        String getTime = "";
        Double totleReceivable = 0.00;
        Double totleFoldingPay = 0.00;
        Double totleServiceActualPay = 0.00;
        Double accountArrears = 0.00;
        for (PayServiceInfo info : payServiceInfoList) {
            if (info != null) {
                if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                    if (info.getPayServiceNum() != null) {
                        totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
                    }
                    if (info.getFoldingPay() != null) {
                        totleFoldingPay += info.getFoldingPay();
                    }
                    if (info.getServiceActualPay() != null) {
                        totleServiceActualPay += info.getServiceActualPay();
                    }
                    if (info.getArrears() != null) {
                        accountArrears += info.getArrears();
                    }
                    info.setTotleReceivable(totleReceivable);
                    info.setTotleFoldingPay(totleFoldingPay);
                    info.setTotleServiceActualPay(totleServiceActualPay);
                    info.setAccountArrears(accountArrears);
                }
                getTime = info.getGetTime();
            }
        }
        model.addAttribute("payServiceInfoList", payServiceInfoList);
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("customerId", customerId);
        model.addAttribute("getTime", getTime);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("operationTime", operationTime);

        return PREFIX + "open_refundMoney.html";
    }

    /**
     * 退款操作 refundMoney
     */
    @RequestMapping(value = "/refundMoneys/{parpams}")
    public String refundMoneys(@PathVariable String parpams, Model model) throws Exception {
        String customerId = parpams.split(",")[0];
        String reservationsId = parpams.split(",")[1];
        String operationTime = parpams.split(",")[2];
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String tableName1 = tableHead + "deal_info";
        String sql = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t1.get_time as getTime,t1.check_status as checkStatus from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id " +
                " where t1.reservations_id='" + reservationsId + "' and  t1.operation_time = '" + operationTime + "'and pay_service_id is not null  group by  operationTime order by operationTime desc";
        List<PayServiceInfo> payServiceInfoList = sqlMapper.selectList(sql, PayServiceInfo.class);
        String sql1 = "select t2.customer_name as customerName,t2.reservations_id as reservationsId,t2.medical_record_number as medicalRecordNumber," +
                "  (CASE t2.customer_sex  " +
                "  WHEN 1 THEN  " +
                "  '男'  " +
                "  WHEN 2 THEN  " +
                "  '女'  " +
                "  ELSE  " +
                "  '未知'  " +
                "  END  " +
                " ) as sex ,t2.customer_age as customerAge,t2.customer_phone as customerPhone ,t2.field_tc as fieldTc" +
                " from " + this.getTableName() + " t2 where id='" + customerId + "'";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        String getTime = "";
        Double totleReceivable = 0.00;
        Double totleFoldingPay = 0.00;
        Double totleServiceActualPay = 0.00;
        Double accountArrears = 0.00;
        for (PayServiceInfo info : payServiceInfoList) {
            if (info != null) {
                if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                    if (info.getPayServiceNum() != null) {
                        totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
                    }
                    if (info.getFoldingPay() != null) {
                        totleFoldingPay += info.getFoldingPay();
                    }
                    if (info.getServiceActualPay() != null) {
                        totleServiceActualPay += info.getServiceActualPay();
                    }
                    if (info.getArrears() != null) {
                        accountArrears += info.getArrears();
                    }
                    info.setTotleReceivable(totleReceivable);
                    info.setTotleFoldingPay(totleFoldingPay);
                    info.setTotleServiceActualPay(totleServiceActualPay);
                    info.setAccountArrears(accountArrears);
                }
                getTime = info.getGetTime();
            }
        }
        model.addAttribute("payServiceInfoList", payServiceInfoList);
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("customerId", customerId);
        model.addAttribute("getTime", getTime);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("operationTime", operationTime);

        return PREFIX + "open_refundMoneys.html";
    }


    /**
     * 跳转到看诊记录
     */
    @RequestMapping(value = "/deal_detail/{reservationsId}")
    public String dealDetail(Model model, @PathVariable String reservationsId) {
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        List<DealInfo> dealInfoInfoList = service.getDealInfoInfoList(reservationsId);
        String sql = "select t2.customer_name as customerName,t2.reservations_id as reservationsId,t2.medical_record_number as medicalRecordNumber," +
                "  (CASE t2.customer_sex  " +
                "  WHEN 1 THEN  " +
                "  '男'  " +
                "  WHEN 2 THEN  " +
                "  '女'  " +
                "  ELSE  " +
                "  '未知'  " +
                "  END  " +
                " ) as sex ,t2.customer_age as customerAge,t2.customer_phone as customerPhone ,t2.field_tc as tcName" +
                " from " + this.getTableName() + " t2 where reservations_id='" + reservationsId + "' order by  arrival_time desc limit 0,1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql, ConsultantInfo.class);
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("dealInfoInfoList", dealInfoInfoList);
        return PREFIX + "deal_detail.html";
    }

    @RequestMapping(value = "/to_noDeal/{ids}")
    public String toNoDeal(Model model, @PathVariable String ids) {
        String customerId = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String operationTime = ids.split(",")[2];
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(operationTime)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        List<PayServiceInfo> payServiceInfoList = service.getPayServiceInfoList();
        String sql = "select t2.id as customerId,t2.reservations_id as reservationsId,t2.customer_phone as customerPhone,t2.customer_name as customerName,t2.medical_record_number as medicalRecordNumber" +
                ",(\n" +
                "        CASE t2.customer_sex\n" +
                "        WHEN 1 THEN\n" +
                "            '男'\n" +
                "        WHEN 2 THEN\n" +
                "            '女'\n" +
                "        ELSE\n" +
                "            '未知'\n" +
                "        END\n" +
                "    ) as sex,t2.customer_age as customerAge ,t2.field_tc as tcName" +
                " from " + this.getTableName() + " t2 where id='" + customerId + "'";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql, ConsultantInfo.class);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("payServiceInfoList", payServiceInfoList);
        model.addAttribute("customerId", customerId);
        model.addAttribute("payServiceId", payServiceInfoList.get(0).getId());
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("operationTime", operationTime);
        return PREFIX + "no_deal.html";
    }

    @RequestMapping(value = "/to_toVoid/{ids}")
    public String toToVoid(Model model, @PathVariable String ids) {
        String customerId = ids.split(",")[0];
        String reservationsId = ids.split(",")[1];
        String operationTime = ids.split(",")[2];
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(operationTime)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        List<PayServiceInfo> payServiceInfoList = service.getPayServiceInfoList();
        String sql = "select t2.id as customerId,t2.reservations_id as reservationsId,t2.customer_phone as customerPhone,t2.customer_name as customerName,t2.medical_record_number as medicalRecordNumber" +
                ",if(t2.customer_sex=1,'男','女') as sex,t2.customer_age as customerAge ,t2.field_tc as tcName" +
                " from " + this.getTableName() + " t2 where id='" + customerId + "'";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql, ConsultantInfo.class);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("payServiceInfoList", payServiceInfoList);
        model.addAttribute("customerId", customerId);
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("operationTime", operationTime);
        return PREFIX + "to_void.html";
    }

    @RequestMapping(value = "/addPayment")
    @ResponseBody
    public int addPayment(@Valid PaymentInfo info, BindingResult result) throws Exception {
        if (result.hasErrors()) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName = tableHead + "recharge_info";
        String tableName1 = tableHead + "deal_info";
        String tableName2 = tableHead + "customer_info";
        String id = CommUtils.getUUID();
        Double accountArrears = info.getTotleFoldingPay() - info.getAmountOfPayment();
        String sql1 = "INSERT INTO " + tableName + " (`id`,`customer_id`,`status`,`reservations_id`, `record_people`, `actual_account_balance`,`account_arrears`,`record_time`,`operation_time`) VALUES" +
                "('" + id + "','" + info.getId() + "'," + 1 + ",'" + info.getReservationsId() + "','" + ShiroKit.getUser().getAccount() + "" +
                "'," + info.getAmountOfPayment() + ", " + accountArrears + " ,'" + DateTimeKit.now() + "','" + info.getOperationTime() + "');";
        String sumSql = "select sum(folding_pay) as foldingPay from " + tableName1 + " where reservations_id='" + info.getReservationsId() + "' and operation_time='" + info.getOperationTime() + "'";
        PaymentInfo paymentInfo = sqlMapper.selectOne(sumSql, PaymentInfo.class);
        Double sp = 0.00;
        if (paymentInfo.getFoldingPay() == 0) {
            sp = 0.00;
        } else {
            sp = info.getAmountOfPayment() / paymentInfo.getFoldingPay();
        }
        String sql = "update " + tableName1 + " set deal_status='已成交',service_actual_pay=folding_pay * " + sp + "" +
                " where reservations_id='" + info.getReservationsId() + "' and operation_time='" + info.getOperationTime() + "'";
        String updateSql = "update " + this.getTableName() + " set deal_status='已成交' where id='" + info.getId() + "'  ";
        String updateSql2 = "update reservations_info set deal_status='已成交' where  id='" + info.getReservationsId() + "' ";
        String selectCustomerStatus = "select id,customer_status as customerStatus from " + this.getTableName() + " where id='" + info.getId() + "' ";
        CustomerInfo customerInfo = sqlMapper.selectOne(selectCustomerStatus, CustomerInfo.class);
        if ("复诊".equals(customerInfo.getCustomerStatus())) {
            String updatesql3 = "update " + tableName2 + " a set a.customer_status='老客'  where id='" + info.getId() + "'  ";
            sqlMapper.update(updatesql3);
        }
        sqlMapper.update(updateSql2);
        sqlMapper.update(updateSql);
        sqlMapper.insert(sql1);
        return sqlMapper.update(sql);
    }

    @RequestMapping(value = "/addSupplement")
    @ResponseBody
    public int addSupplement(@Valid PaymentInfo info, BindingResult result) throws Exception {
        if (result.hasErrors()) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName = tableHead + "recharge_info";
        String tableName1 = tableHead + "deal_info";
        String tableName2 = tableHead + "customer_info";
        String id = CommUtils.getUUID();
        Random rand = new Random();
        int randomNumber = rand.nextInt(9999);
        id = id + randomNumber;
        randomNumber = rand.nextInt(9999);
        id = randomNumber + id;
        String sumSql = "select sum(folding_pay) as foldingPay  from " + tableName1 + "  where reservations_id='" + info.getReservationsId() + "' and operation_time='" + info.getOperationTime() + "';";
        PaymentInfo paymentInfo = sqlMapper.selectOne(sumSql, PaymentInfo.class);
        String updateSql = "update " + tableName1 + " a set a.service_actual_pay=service_actual_pay + folding_pay*" + info.getSupplementOfPayment() / paymentInfo.getFoldingPay() + " where a.reservations_id='" + info.getReservationsId() + "' and a.operation_time='" + info.getOperationTime() + "';";
        String sql = "INSERT INTO `" + tableName + "` (`id`, `status`, `customer_id`, `reservations_id`, `record_people`, `recharge_people`, `is_record`, `actual_account_balance` , `account_arrears`, `operation_time`, `record_time` ) VALUES" +
                "('" + id + "', " + 1 + " ,'" + info.getId() + "','" + info.getReservationsId() + "','" + ShiroKit.getUser().getAccount() + "','','是','" + info.getSupplementOfPayment() + "' ,'-" + info.getSupplementOfPayment() + "','" + info.getOperationTime() + "','" + DateTimeKit.now() + "')";
        String updatesql2 = "update " + tableName2 + " a set a.actual_account_balance=actual_account_balance+" + info.getSupplementOfPayment() + " , a.account_arrears=a.account_arrears-" + info.getSupplementOfPayment() + " where id='" + info.getId() + "'";
        sqlMapper.update(updatesql2);
        sqlMapper.update(updateSql);
        return sqlMapper.insert(sql);
    }


    /**
     * 执行补欠款操作
     *
     * @param inputNum
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/fillOwe", method = RequestMethod.POST)
    @ResponseBody
    public int fillOwe(String inputNum) throws Exception {
        String payServiceName[] = inputNum.split("#");
        int count = payServiceName.length;
        String fillMoney = "";
        String getId = "";
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName1 = tableHead + "deal_info";
        String time = DateTimeKit.now();
        for (int i = 0; i < count; i++) {
            fillMoney = inputNum.split("#")[i].split(",")[0];
            getId = inputNum.split("#")[i].split(",")[1];
            String id = CommUtils.getUUID().substring(0, 10) + DateTimeKit.now();
            String insertSql = "insert into " + tableName1 + " " +
                    "(id,customer_id,reservations_id,pay_service_id,tc_name,pay_service_num,service_actual_pay," +
                    "remarks,deal_status,operation_time,get_time,outpatient_name,folding_pay,pay_service,left_up," +
                    "left_down,right_up,right_down,doctor,nurse,id2,is_do,arrears)  " +
                    "select '" + id + "',customer_id,reservations_id,pay_service_id,tc_name,pay_service_num," +
                    fillMoney + ",remarks,'已开单', operation_time  ,'" + time + "',outpatient_name," +
                    "folding_pay,pay_service,left_up, left_down,right_up,right_down,doctor,nurse,id2,3,'-" + fillMoney + "'  from " + tableName1 + " " +
                    "where id='" + getId + "'";
            sqlMapper.insert(insertSql);
        }
        return 1;
    }

    @RequestMapping(value = "/updateDoctorNurse", method = RequestMethod.POST)
    @ResponseBody
    public int updateDoctorNurse(String doctor, String nurse, String customerId, String operationTime, String id2) throws Exception {
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(operationTime)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName1 = tableHead + "deal_info";
        if (doctor == null || doctor == "") {
            doctor = "";
        }
        if (nurse == null || nurse == "") {
            nurse = "";
        }
        String sql = "update " + tableName1 + " a set a.doctor='" + doctor + "',a.nurse='" + nurse + "' " +
                "where a.customer_id='" + customerId + "' and a.operation_time='" + operationTime + "' and a.id2='" + id2 + "'";
        sqlMapper.update(sql);

        String sql2 = "insert into distributive_doctor_log (customer_id,deal_id,tc_name,distributive_doctor,distributive_nurse,update_name,distributive_time )  " +
                " select customer_id,id2,'" + ShiroKit.getUser().getAccount() + "',doctor,nurse,'" + ShiroKit.getUser().getAccount() + "','"
                + DateTimeKit.now() + "' from " + tableName1 + " where customer_id ='" + customerId + "' and  operation_time='" + operationTime + "' and  id='" + id2 + "'";
        return sqlMapper.insert(sql2);

    }


    /**
     * 执行退款操作
     *
     * @param parpams
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/returnMonrys", method = RequestMethod.POST)
    @ResponseBody
    public int returnMonrys(String parpams) throws Exception {
        String payServiceName[] = parpams.split("#");
        int count = payServiceName.length;
        String fillMoney = "";
        String getId = "";
        String dealtype = "";  //退款类型
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName1 = tableHead + "deal_info";
        String time = DateTimeKit.now();
        for (int i = 0; i < count; i++) {
            fillMoney = parpams.split("#")[i].split(",")[0];
            getId = parpams.split("#")[i].split(",")[1];
            dealtype = parpams.split("#")[i].split(",")[2];
            String id = CommUtils.getUUID().substring(0, 10) + DateTimeKit.now();
            String insertSql = "insert into " + tableName1 + " " +
                    "(id,customer_id,reservations_id,pay_service_id,tc_name,pay_service_num,service_actual_pay," +
                    "remarks,deal_status,operation_time,get_time,outpatient_name,folding_pay,pay_service,left_up," +
                    "left_down,right_up,right_down,doctor,nurse,id2,arrears,is_do)  " +
                    "select '" + id + "',customer_id,reservations_id,pay_service_id,tc_name,pay_service_num," +
                    "-" + fillMoney + ",remarks,'已开单', operation_time  ,'" + time + "',outpatient_name," +
                    "folding_pay,pay_service ,left_up, left_down,right_up,right_down,doctor,nurse,id2, ";
            if (dealtype.equals("1")) {  //不做了
                insertSql += "0,1";
            } else if (dealtype.equals("2")) {  //继续做
                insertSql += "" + fillMoney + ",2";
            } else if (dealtype.equals("3")) {  //退项目
                insertSql += "0,4";
//                String sql2="select id2 from " + tableName1 + " where id='" + getId + "' ";
//                RechargeInfo info = sqlMapper.selectOne(sql2, RechargeInfo.class);
//                String updateSql = "update " + tableName1 + " set arrears=0 where id2= '" +info.getId2()+"'";
//                sqlMapper.update(updateSql);
            }
            insertSql += " from " + tableName1 + " where id='" + getId + "'";
            sqlMapper.insert(insertSql);
        }
        return 1;
    }


    /**
     * 跳转到看诊记录
     */
    @RequestMapping(value = "/diagnosis_details/{cr}")
    public String diagnosisDetails(Model model, @PathVariable String cr) {
        String id = cr.split(",")[0];
        String reservationsId = cr.split(",")[1];
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(id)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String selectsql = "select * from " + this.getTableName() + " where reservations_id='" + reservationsId + "' order by arrival_time asc limit 0,1";
        CustomerInfo customerInfo = sqlMapper.selectOne(selectsql, CustomerInfo.class);
        List<ConsultantInfo> consultantInfoList = service.getConsultantInfoList(reservationsId);
        String tcName = "";
        String firstVisitDate = "";
        if (customerInfo != null) {
            tcName = customerInfo.getFieldTc();
            firstVisitDate = customerInfo.getFirstVisitDate();
        }
        String sql = "select t2.id as customerId,t2.reservations_id as reservationsId,t2.customer_name as customerName,t2.medical_record_number as medicalRecordNumber" +
                ",t2.customer_sex as customerSex,t2.customer_age as customerAge ,t2.field_tc as tcName" +
                " from " + this.getTableName() + " t2 where reservations_id='" + reservationsId + "' order by t2.arrival_time desc limit 0,1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql, ConsultantInfo.class);
        String sql1 = "select * from reservations_info where id='" + reservationsId + "' limit 0,1";
        ReservationsInfo reservationsInfo = sqlMapper.selectOne(sql1, ReservationsInfo.class);
        List<AddVisitedInfo> revisitRecordList = service.getRevisitRecordList(reservationsId);
        for (ConsultantInfo infos : consultantInfoList) {
            if (infos.getDiagnosisTime() != "" && infos.getDiagnosisTime() != null) {
                infos.setDiagnosisTimeOne(infos.getDiagnosisTime().substring(0, 10));
                infos.setDiagnosisTimeTwo(infos.getDiagnosisTime().substring(11, infos.getDiagnosisTime().length()));
            }
        }
        model.addAttribute("revisitRecordList", revisitRecordList);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("reservationsInfo", reservationsInfo);
        model.addAttribute("reservations", ShiroKit.getUser().getAccount());
        model.addAttribute("consultantInfoList", consultantInfoList);
        model.addAttribute("tcName", tcName);
        model.addAttribute("arrivalStore", customerInfo.getArrivalStore());
        model.addAttribute("id", id);
        model.addAttribute("firstVisitDate", firstVisitDate);
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "diagnosis_details.html";
    }

    @RequestMapping(value = "/diagnosis_detail/{id}")
    public String diagnosisDetail(Model model, @PathVariable String id) {
        if (ToolUtil.isEmpty(id)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        List<ConsultantInfo> consultantInfoList = service.getConsultantInfoList(id);
        String tcName = "";
        String firstVisitDate = "";
        String sql = "select t2.id as customerId,t2.reservations_id as reservationsId,t2.customer_name as customerName,t2.medical_record_number as medicalRecordNumber" +
                ",t2.customer_sex as customerSex,t2.customer_age as customerAge ,t2.field_tc as tcName" +
                " from " + this.getTableName() + " t2 where reservations_id='" + id + "' order by t2.arrival_time desc limit 0,1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql, ConsultantInfo.class);
        String sql1 = "select * from reservations_info where id='" + id + "' limit 0,1";
        ReservationsInfo reservationsInfo = sqlMapper.selectOne(sql1, ReservationsInfo.class);
        if (reservationsInfo != null) {
            tcName = reservationsInfo.getTcName();
            firstVisitDate = reservationsInfo.getFirstVisitDate();
        }
        List<AddVisitedInfo> revisitRecordList = service.getRevisitRecordList(id);
        model.addAttribute("revisitRecordList", revisitRecordList);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("reservationsInfo", reservationsInfo);
        model.addAttribute("reservations", ShiroKit.getUser().getAccount());
        model.addAttribute("consultantInfoList", consultantInfoList);
        model.addAttribute("tcName", tcName);
        model.addAttribute("firstVisitDate", firstVisitDate);
        model.addAttribute("reservationsId", id);
        return PREFIX + "diagnosis_detail.html";
    }


    @RequestMapping(value = "/getDiagnosisContent", method = RequestMethod.POST)
    @ResponseBody
    public ConsultantInfo getDiagnosisContent(String diagnosisTime, String reservationsId) {
        diagnosisTime = diagnosisTime.substring(0, 10) + " " + diagnosisTime.substring(10, 18);
        String sql = "select id as id ,reservations_id as reservationsId,customer_id as customerId,diagnosis_content as diagnosisContent," +
                "tc_name as tcName from " +
                "tc_diagnosis_info where reservations_id='" + reservationsId + "'and diagnosis_time='" + diagnosisTime + "'";
        ConsultantInfo info = sqlMapper.selectOne(sql, ConsultantInfo.class);
//        String sql1 = "select table_name from information_schema.tables where table_schema='crms'\n" +
//                "and table_name like  '%customer_info%'";
//        List<ReservationsInfo> list = sqlMapper.selectList(sql1, ReservationsInfo.class);
//        String sql2 = "select * from ( select *  from " + list.get(0).getTableName() + "";
//        for (int i = 1; i < list.size(); i++) {
//            sql2 += " union all select *  from " + list.get(i).getTableName() + "";
//        }
//        sql2 += " ) t where t.id='" + info.getCustomerId() + "'";
//        ConsultantInfo info2 = sqlMapper.selectOne(sql2, ConsultantInfo.class);
//        if (info2 != null) {
//            if (info2.getCustomerSex() == 1) {
//                info.setSex("男");
//            } else {
//                info.setSex("女");
//            }
//        }
//        info.setTcName(info2.getFieldTc());
//        info.setMedicalRecordNumber(info2.getMedicalRecordNumber());
//        info.setCustomerName(info2.getCustomerName());
//        info.setCustomerPhone(info2.getCustomerPhone());
//        info.setCustomerAge(info2.getCustomerAge());
        return info;
    }

    @RequestMapping(value = "/getVisitContent", method = RequestMethod.POST)
    @ResponseBody
    public CustomerInfo getVisitContent(String startTime, String reservationsId) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName = tableHead + "customer_info";
        startTime = startTime.substring(0, 10) + " " + startTime.substring(10, startTime.length());
        String sql = "select id as id ,reservations_id as reservationsId,field_tc as fieldTc,customer_status as customerStatus,doctor as doctor,appointment_pay_service as appointmentPayService, " +
                "remarks as remarks,archiving as archiving,left(create_appointment_time,19) as createAppointmentTime from " + tableName + " where reservations_id='" + reservationsId + "'and start_time='" + startTime + "'";
        CustomerInfo info = sqlMapper.selectOne(sql, CustomerInfo.class);
        return info;
    }


    @RequestMapping(value = "/getDealContent", method = RequestMethod.POST)
    @ResponseBody
    public DealInfo getDealContent(String operationTime, String reservationsId) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName = tableHead + "deal_info";
        String sql = "select id as id ,is_deal as isDeal,tc_name as tcName ,remarks as remarks," +
                "no_deal_cause as noDealCause ,outpatient_name as outpatientName" +
                " from " + tableName + " where reservations_id='" + reservationsId + "'and operation_time='" + operationTime + "'";
        DealInfo info = sqlMapper.selectOne(sql, DealInfo.class);
        return info;
    }

    @RequestMapping(value = "/getOpenBillList", method = RequestMethod.POST)
    @ResponseBody
    public List<PayServiceInfo> getOpenBillList(String operationTime, String getTime, String customerId, String
            reservationsId, String filterMoney) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName1 = tableHead + "deal_info";
//        if (getTime == null || getTime == "") {
//            getTime = " is null ";
//        } else {
//            getTime = "='" + getTime + "'";
//        }
        if (StringUtil.isNotEmpty(operationTime) && operationTime.length() == 18) {//yyyy-mm-ddHH:mm:ss --- yyyy-mm-dd HH:mm:ss
            operationTime = operationTime.substring(0, 10) + " " + operationTime.substring(10);//中间加入空格
        }
//        String filterContion = "";//是否过滤出值有欠费的项目
//        if (StringUtil.isNotEmpty(filterMoney)) {
//            filterContion = " and t1.arrears > 0  ";
//        }
       /* String sql1 = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.doctor as doctor ,t1.nurse as nurse,t1.left_up as leftUp ,t1.left_down as leftDown ,t1.right_up as rightUp ,t1.right_down as rightDown ,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t3.customer_name as customerName ,t3.medical_record_number as medicalRecordNumber,t3.customer_phone as customerPhone,t3.customer_age as customerAge,\n" +
                "(\n" +
                "        CASE t3.customer_sex\n" +
                "        WHEN 1 THEN\n" +
                "            '男'\n" +
                "        WHEN 2 THEN\n" +
                "            '女'\n" +
                "        ELSE\n" +
                "            '未知'\n" +
                "        END\n" +
                "    ) as sex ,t3.arrival_store as arrivalStore,t1.tc_name as fieldTc ,id2 as id2 from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id left join " + this.getTableName() + " t3 on t1.customer_id=t3.id" +
                " where t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "' and t1.deal_status='已成交' ";
        List<PayServiceInfo> openBillList1 = sqlMapper.selectList(sql1, PayServiceInfo.class);//查询当前所有已成交的记录
        String sql2 = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t1.get_time as getTime ,id2 as id2 from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id " +
                " where t1.reservations_id='" + reservationsId + "' and pay_service_id is not null and t1.operation_time=t1.get_time \n" +
                " and t1.operation_time='" + operationTime + "' order by operationTime desc";
        List<PayServiceInfo> openBillList2 = sqlMapper.selectList(sql2, PayServiceInfo.class);//查询初始开单成交记录
        String sql3 = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId,t1.get_time as getTime ,t1.outpatient_name as outpatientName , t1.deal_status as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " (select sum(service_actual_pay) from " + tableName1 + " where customer_id=t1.customer_id and operation_time=t1.operation_time and id2=t1.id2 and deal_status='已成交')  as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.doctor as doctor ,t1.nurse as nurse,t1.left_up as leftUp ,t1.left_down as leftDown ,t1.right_up as rightUp ,t1.right_down as rightDown ,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t3.customer_name as customerName ,t3.medical_record_number as medicalRecordNumber,t3.customer_phone as customerPhone,t3.customer_age as customerAge,\n" +
                "if(t3.customer_sex='1','男','女') as sex ,t3.arrival_store as arrivalStore,t1.tc_name as fieldTc ,id2 as id2 from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id left join " + this.getTableName() + " t3 on t1.customer_id=t3.id" +
                " where t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "'  and t1.deal_status='已成交' order by t1.get_time desc limit 0," + openBillList2.size() + "";
        List<PayServiceInfo> openBillList3 = sqlMapper.selectList(sql3, PayServiceInfo.class);//查询最近已成交的记录
        if (openBillList3.size() == 0) {
            String sql4 = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId,t1.get_time as getTime ,t1.outpatient_name as outpatientName , t1.deal_status as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                    " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                    " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.doctor as doctor ,t1.nurse as nurse,t1.left_up as leftUp ,t1.left_down as leftDown ,t1.right_up as rightUp ,t1.right_down as rightDown ,t1.pay_service as payService," +
                    "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                    "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                    "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t3.customer_name as customerName ,t3.medical_record_number as medicalRecordNumber,t3.customer_phone as customerPhone,t3.customer_age as customerAge,\n" +
                    "(\n" +
                    "        CASE t3.customer_sex\n" +
                    "        WHEN 1 THEN\n" +
                    "            '男'\n" +
                    "        WHEN 2 THEN\n" +
                    "            '女'\n" +
                    "        ELSE\n" +
                    "            '未知'\n" +
                    "        END\n" +
                    "    ) as sex ,t3.arrival_store as arrivalStore,t1.tc_name as fieldTc ,id2 as id2 from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id left join " + this.getTableName() + " t3 on t1.customer_id=t3.id" +
                    " where t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "'  and t1.deal_status!='未成交' and t1.deal_status!='作废'  order by t1.get_time desc limit 0," + openBillList2.size() + "";
            String sql5 = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                    " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                    " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.doctor as doctor ,t1.nurse as nurse,t1.left_up as leftUp ,t1.left_down as leftDown ,t1.right_up as rightUp ,t1.right_down as rightDown ,t1.pay_service as payService," +
                    "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                    "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                    "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t3.customer_name as customerName ,t3.medical_record_number as medicalRecordNumber,t3.customer_phone as customerPhone,t3.customer_age as customerAge,\n" +
                    "if(t3.customer_sex='1','男','女') as sex ,t3.arrival_store as arrivalStore,t1.tc_name as fieldTc ,id2 as id2 from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id left join " + this.getTableName() + " t3 on t1.customer_id=t3.id" +
                    " where t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "' and t1.deal_status!='未成交' and t1.deal_status!='作废' ";

            openBillList3 = sqlMapper.selectList(sql4, PayServiceInfo.class);//查询当前开单除去不做了的记录
            openBillList1 = sqlMapper.selectList(sql5, PayServiceInfo.class);//查询当前开单除去不做了的记录
        }
        Double totleReceivable = 0.00;//总的项目总价，非折后
//        Double totleServiceActualPay = 0.00;//总的实付金额（全部）
        Double totleServiceActualPays = 0.00;//总的实付金额（除去不做的）
        Double totleFoldingPay = 0.00;//总的折后价
        Double accountArrears = 0.00;
        for (PayServiceInfo info : openBillList1) {
            if (info != null) {
                if (info.getServiceActualPay() != null) {
                    totleServiceActualPays += info.getServiceActualPay();
                }
            }
        }
        for (PayServiceInfo info : openBillList3) {
            if (info != null) {
                if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                    if (info.getPayServiceNum() != null) {
                        totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
                    }
                    if (info.getFoldingPay() != null) {
                        totleFoldingPay += info.getFoldingPay();
                    }
                    if (info.getArrears() != null) {
                        accountArrears += info.getArrears();
                    }
//                    if(!info.getOperationTime().equals(info.getGetTime())){
//                        info.setDealStatus("已成交");
//                    }
                    info.setTotleReceivable(totleReceivable);
                    info.setTotleFoldingPay(totleFoldingPay);
                    info.setTotleServiceActualPay(totleServiceActualPays);
                    info.setAccountArrears(accountArrears);
                }
            }
        }*/
        String sql3 = "SELECT  service_actual_pay  as serviceActualPay, arrears as  arrears, " +
                " t1.id AS id,t1.customer_id AS customerId,t1.reservations_id AS reservationsId,t1.get_time AS getTime,t1.outpatient_name AS outpatientName, " +
                " t1.deal_status AS dealStatus, t1.tc_name AS tcName,t1.pay_service_num AS payServiceNum," +
                " LEFT(t1.operation_time,19) AS operationTime,t1.remarks AS remarks, t1.folding_pay AS foldingPay,t1.to_void_cause AS toVoidCause,t1.doctor AS doctor," +
                " t1.left_up AS leftUp,t1.left_down AS leftDown,t1.right_up AS rightUp,t1.right_down AS rightDown,t1.pay_service AS payService,t2.id AS payServiceId," +
                " t2.department AS department,t2.first_level_project AS firstLevelProject,t2.pay_service_name AS payServiceName, t2.pay_service_price_one AS payServicePriceOne, " +
                " t2.pay_service_price_two AS payServicePriceTwo,t1.to_void_cause AS toVoidCause,t1.no_deal_cause AS noDealCause,t3.customer_name AS customerName," +
                " t3.medical_record_number AS medicalRecordNumber,t3.customer_phone AS customerPhone,t3.customer_age AS customerAge,t1.id2, " +
                " IF(t3.customer_sex='1','男','女') AS sex,t3.arrival_store AS arrivalStore,t1.tc_name AS fieldTc,t1.check_status AS checkStatus  " +
                " from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id left join " + this.getTableName() + " t3 on t1.customer_id=t3.id" +
                " where t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "' and (t1.deal_status='已成交' or t1.deal_status='已开单') GROUP BY t1.id  order by t1.get_time desc ";
        List<PayServiceInfo> openBillList3 = sqlMapper.selectList(sql3, PayServiceInfo.class);
        Double totleReceivable = 0.00;//总的项目总价，非折后
//        Double totleServiceActualPay = 0.00;//总的实付金额（全部）
        Double totleServiceActualPays = 0.00;//总的实付金额（除去不做的）
        Double totleFoldingPay = 0.00;//总的折后价
        Double accountArrears = 0.00;
        for (PayServiceInfo info : openBillList3) {
            if (info != null) {
                if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                    if (info.getPayServiceNum() != null) {
                        totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
                    }
                    if (info.getFoldingPay() != null) {
                        totleFoldingPay += info.getFoldingPay();
                    }
                    if (info.getArrears() != null) {
                        accountArrears += info.getArrears();
                    }
//                    if(!info.getOperationTime().equals(info.getGetTime())){
//                        info.setDealStatus("已成交");
//                    }
                    info.setTotleReceivable(totleReceivable);
                    info.setTotleFoldingPay(totleFoldingPay);
                    info.setTotleServiceActualPay(totleServiceActualPays);
                    info.setAccountArrears(accountArrears);
                }
            }
        }
        return openBillList3;
    }


    @RequestMapping(value = "/getOpenBillListd", method = RequestMethod.POST)
    @ResponseBody
    public List<PayServiceInfo> getOpenBillListd(String operationTime, String getTime, String customerId, String
            reservationsId, String filterMoney) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName1 = tableHead + "deal_info";
//        if (getTime == null || getTime == "") {
//            getTime = " is null ";
//        } else {
//            getTime = "='" + getTime + "'";
//        }
        if (StringUtil.isNotEmpty(operationTime) && operationTime.length() == 18) {//yyyy-mm-ddHH:mm:ss --- yyyy-mm-dd HH:mm:ss
            operationTime = operationTime.substring(0, 10) + " " + operationTime.substring(10);//中间加入空格
        }
//        String filterContion = "";//是否过滤出值有欠费的项目
//        if (StringUtil.isNotEmpty(filterMoney)) {
//            filterContion = " and t1.arrears > 0  ";
//        }
//        String sql1 = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
//                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
//                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.doctor as doctor ,t1.left_up as leftUp ,t1.left_down as leftDown ,t1.right_up as rightUp ,t1.right_down as rightDown ,t1.pay_service as payService," +
//                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
//                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
//                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t3.customer_name as customerName ,t3.medical_record_number as medicalRecordNumber,t3.customer_phone as customerPhone,t3.customer_age as customerAge,\n" +
//                "(\n" +
//                "        CASE t3.customer_sex\n" +
//                "        WHEN 1 THEN\n" +
//                "            '男'\n" +
//                "        WHEN 2 THEN\n" +
//                "            '女'\n" +
//                "        ELSE\n" +
//                "            '未知'\n" +
//                "        END\n" +
//                "    ) as sex ,t3.arrival_store as arrivalStore,t1.tc_name as fieldTc,t1.check_status as checkStatus  from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id left join " + this.getTableName() + " t3 on t1.customer_id=t3.id" +
//                " where t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "' and t1.deal_status='已成交' ";
//        List<PayServiceInfo> openBillList1 = sqlMapper.selectList(sql1, PayServiceInfo.class);//查询当前开单除去不做了的记录
//        String sql2 = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
//                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
//                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.pay_service as payService," +
//                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
//                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
//                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t1.get_time as getTime,t1.check_status as checkStatus  from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id " +
//                " where t1.reservations_id='" + reservationsId + "' and pay_service_id is not null and t1.operation_time=t1.get_time \n" +
//                " and t1.operation_time='" + operationTime + "' order by operationTime desc";
//        List<PayServiceInfo> openBillList2 = sqlMapper.selectList(sql2, PayServiceInfo.class);
//        String sql3 = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId,t1.get_time as getTime ,t1.outpatient_name as outpatientName , t1.deal_status as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
//                " (select sum(service_actual_pay) from " + tableName1 + " where customer_id=t1.customer_id and operation_time=t1.operation_time and id2=t1.id2 and deal_status='已成交')  as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
//                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.doctor as doctor ,t1.left_up as leftUp ,t1.left_down as leftDown ,t1.right_up as rightUp ,t1.right_down as rightDown ,t1.pay_service as payService," +
//                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
//                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
//                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t3.customer_name as customerName ,t3.medical_record_number as medicalRecordNumber,t3.customer_phone as customerPhone,t3.customer_age as customerAge,\n" +
//                "if(t3.customer_sex='1','男','女') as sex ,t3.arrival_store as arrivalStore,t1.tc_name as fieldTc,t1.check_status as checkStatus  from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id left join " + this.getTableName() + " t3 on t1.customer_id=t3.id" +
//                " where t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "'  and t1.deal_status='已成交' order by t1.get_time desc limit 0," + openBillList2.size() + "";
//        List<PayServiceInfo> openBillList3 = sqlMapper.selectList(sql3, PayServiceInfo.class);//查询当前开单除去不做了的记录
//        Double totleReceivable = 0.00;//总的项目总价，非折后
////        Double totleServiceActualPay = 0.00;//总的实付金额（全部）
//        Double totleServiceActualPays = 0.00;//总的实付金额（除去不做的）
//        Double totleFoldingPay = 0.00;//总的折后价
//        Double accountArrears = 0.00;
//
//        for (PayServiceInfo info1 : openBillList1) {
//            if (info1 != null) {
//                if (info1.getServiceActualPay() != null) {
//                    totleServiceActualPays += info1.getServiceActualPay();
//                }
//            }
//        }
//
//        for (PayServiceInfo info : openBillList3) {
//            if (info != null) {
//                if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
//                    if (info.getPayServiceNum() != null) {
//                        totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
//                    }
//                    if (info.getFoldingPay() != null) {
//                        totleFoldingPay += info.getFoldingPay();
//                    }
//                    if (info.getArrears() != null) {
//                        accountArrears += info.getArrears();
//                    }
////                    if(!info.getOperationTime().equals(info.getGetTime())){
////                        info.setDealStatus("已成交");
////                    }
//                    info.setTotleReceivable(totleReceivable);
//                    info.setTotleFoldingPay(totleFoldingPay);
//                    info.setTotleServiceActualPay(totleServiceActualPays);
//                    info.setAccountArrears(accountArrears);
//                }
//            }
//        }
        String sql3 = "SELECT SUM(service_actual_pay) as serviceActualPay,sum(arrears) as  accountArrears, " +
                " t1.id AS id,t1.customer_id AS customerId,t1.reservations_id AS reservationsId,t1.get_time AS getTime,t1.outpatient_name AS outpatientName, " +
                " t1.deal_status AS dealStatus, t1.tc_name AS tcName,t1.pay_service_num AS payServiceNum," +
                " LEFT(t1.operation_time,19) AS operationTime,t1.remarks AS remarks, t1.folding_pay AS foldingPay,t1.to_void_cause AS toVoidCause,t1.doctor AS doctor," +
                " t1.left_up AS leftUp,t1.left_down AS leftDown,t1.right_up AS rightUp,t1.right_down AS rightDown,t1.pay_service AS payService,t2.id AS payServiceId," +
                " t2.department AS department,t2.first_level_project AS firstLevelProject,t2.pay_service_name AS payServiceName, t2.pay_service_price_one AS payServicePriceOne, " +
                " t2.pay_service_price_two AS payServicePriceTwo,t1.to_void_cause AS toVoidCause,t1.no_deal_cause AS noDealCause,t3.customer_name AS customerName," +
                " t3.medical_record_number AS medicalRecordNumber,t3.customer_phone AS customerPhone,t3.customer_age AS customerAge,t1.id2, " +
                " IF(t3.customer_sex='1','男','女') AS sex,t3.arrival_store AS arrivalStore,t1.tc_name AS fieldTc,t1.check_status AS checkStatus  " +
                " from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id left join " + this.getTableName() + " t3 on t1.customer_id=t3.id" +
                " where t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "'  and t1.deal_status='已成交' GROUP BY t1.id2  order by t1.get_time desc ";
        List<PayServiceInfo> openBillList3 = sqlMapper.selectList(sql3, PayServiceInfo.class);
        return openBillList3;
    }

    @RequestMapping(value = "/getOpenBillListjz", method = RequestMethod.POST)
    @ResponseBody
    public List<PayServiceInfo> getOpenBillListjz(String operationTime, String getTime, String customerId, String
            reservationsId, String filterMoney) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName1 = tableHead + "deal_info";
        if (StringUtil.isNotEmpty(operationTime) && operationTime.length() == 18) {//yyyy-mm-ddHH:mm:ss --- yyyy-mm-dd HH:mm:ss
            operationTime = operationTime.substring(0, 10) + " " + operationTime.substring(10);//中间加入空格
        }
//        String sql2 = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
//                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
//                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.pay_service as payService," +
//                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
//                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
//                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t1.get_time as getTime from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id " +
//                " where t1.reservations_id='" + reservationsId + "' and pay_service_id is not null and t1.operation_time=t1.get_time \n" +
//                " and t1.operation_time='" + operationTime + "' order by operationTime desc";
//        List<PayServiceInfo> openBillList2 = sqlMapper.selectList(sql2, PayServiceInfo.class);
        String sql3 = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , '已成交'  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.doctor as doctor ,t1.left_up as leftUp ,t1.left_down as leftDown ,t1.right_up as rightUp ,t1.right_down as rightDown ,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t3.customer_name as customerName ,t3.medical_record_number as medicalRecordNumber,t3.customer_phone as customerPhone,t3.customer_age as customerAge,\n" +
                "(\n" +
                "        CASE t3.customer_sex\n" +
                "        WHEN 1 THEN\n" +
                "            '男'\n" +
                "        WHEN 2 THEN\n" +
                "            '女'\n" +
                "        ELSE\n" +
                "            '未知'\n" +
                "        END\n" +
                "    ) as sex ,t3.arrival_store as arrivalStore,t1.tc_name as fieldTc from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id left join " + this.getTableName() + " t3 on t1.customer_id=t3.id" +
                " where t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "' and  t1.get_time='" + getTime + "'";
        List<PayServiceInfo> openBillList3 = sqlMapper.selectList(sql3, PayServiceInfo.class);//查询当前开单除去不做了的记录 and t1.deal_status='已成交'
        Double totleReceivable = 0.00;//总的项目总价，非折后
        Double totleServiceActualPays = 0.00;//总的实付金额（除去不做的）
        Double totleFoldingPay = 0.00;//总的折后价
        Double accountArrears = 0.00;
        for (PayServiceInfo info : openBillList3) {
            if (info != null) {
                if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                    if (info.getPayServiceNum() != null) {
                        totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
                    }
                    if (info.getFoldingPay() != null) {
                        totleFoldingPay += info.getFoldingPay();
                    }
                    if (info.getArrears() != null) {
                        accountArrears += info.getArrears();
                    }
                    if (info.getServiceActualPay() != null) {
                        totleServiceActualPays += info.getServiceActualPay();
                    }
                    info.setTotleReceivable(totleReceivable);
                    info.setTotleFoldingPay(totleFoldingPay);
                    info.setTotleServiceActualPay(totleServiceActualPays);
                    info.setAccountArrears(accountArrears);
                }
            }
        }

        return openBillList3;
    }


    @RequestMapping(value = "/getOpenBillLisChengjiao", method = RequestMethod.POST)
    @ResponseBody
    public List<PayServiceInfo> getOpenBillLisChengjiao(String operationTime, String getTime, String customerId, String
            reservationsId, String filterMoney) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName1 = tableHead + "deal_info";
        String tableName4 = tableHead + "recharge_info";
//        if (getTime == null || getTime == "") {
//            getTime = " is null ";
//        } else {
//            getTime = "='" + getTime + "'";
//        }
        if (StringUtil.isNotEmpty(operationTime) && operationTime.length() == 18) {//yyyy-mm-ddHH:mm:ss --- yyyy-mm-dd HH:mm:ss
            operationTime = operationTime.substring(0, 10) + " " + operationTime.substring(10);//中间加入空格
        }
//        String filterContion = "";//是否过滤出值有欠费的项目
//        if (StringUtil.isNotEmpty(filterMoney)) {
//            filterContion = " and t1.arrears > 0  ";
//        }
//        String sql1 = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
//                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
//                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.doctor as doctor ,t1.left_up as leftUp ,t1.left_down as leftDown ,t1.right_up as rightUp ,t1.right_down as rightDown ,t1.pay_service as payService," +
//                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
//                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
//                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t3.customer_name as customerName ,t3.medical_record_number as medicalRecordNumber,t3.customer_phone as customerPhone,t3.customer_age as customerAge,\n" +
//                "(\n" +
//                "        CASE t3.customer_sex\n" +
//                "        WHEN 1 THEN\n" +
//                "            '男'\n" +
//                "        WHEN 2 THEN\n" +
//                "            '女'\n" +
//                "        ELSE\n" +
//                "            '未知'\n" +
//                "        END\n" +
//                "    ) as sex ," +
//                "t1.doctor as doctor ,\n" +
//                "(case \n" +
//                "  when t1.is_do=1   then '不做了'\n" +
//                "  when t1.is_do=2   then '继续做'\n" +
//                "  when t1.is_do=3   then '补款'\n" +
//                "  when t1.is_do=4   then '退项目'\n" +
//                "  when t1.is_do=5   then '结账'\n" +
//                "  when t1.is_do=6   then '作废'\n" +
//                " end\n" +
//                "  ) isDoName,t4.recharge_people as  rechargePeople,t4.checkout_method as checkoutMethod," +
//                "t3.arrival_store as arrivalStore,t1.tc_name as fieldTc,t1.check_status as checkStatus  from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id " +
//                " left join " + this.getTableName() + " t3 on t1.customer_id=t3.id " +
//                " left join " + tableName4 + " t4 on t4.id2=t1.id" +
//                " where t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "' and t1.deal_status='已成交' ";
//        List<PayServiceInfo> openBillList1 = sqlMapper.selectList(sql1, PayServiceInfo.class);//查询当前开单除去不做了的记录
//        String sql2 = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
//                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
//                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.pay_service as payService," +
//                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
//                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
//                "t1.to_void_cause as toVoidCause ," +
//                "t1.no_deal_cause as noDealCause,t1.get_time as getTime,t1.check_status as checkStatus  from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id " +
//                " where t1.reservations_id='" + reservationsId + "' and pay_service_id is not null and t1.operation_time=t1.get_time \n" +
//                " and t1.operation_time='" + operationTime + "' order by operationTime desc";
//        List<PayServiceInfo> openBillList2 = sqlMapper.selectList(sql2, PayServiceInfo.class);
//        String sql3 = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId,t1.get_time as getTime ,t1.outpatient_name as outpatientName , t1.deal_status as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
////                " (select sum(service_actual_pay) from " + tableName1 + " where customer_id=t1.customer_id and operation_time=t1.operation_time and id2=t1.id2 and deal_status='已成交')  as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
//                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
//                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.doctor as doctor ,t1.left_up as leftUp ,t1.left_down as leftDown ,t1.right_up as rightUp ,t1.right_down as rightDown ,t1.pay_service as payService," +
//                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
//                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
//                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t3.customer_name as customerName ,t3.medical_record_number as medicalRecordNumber,t3.customer_phone as customerPhone,t3.customer_age as customerAge,\n" +
//                "if(t3.customer_sex='1','男','女') as sex ," +
//                "t1.doctor as doctor ,\n" +
//                "(case \n" +
//                "  when t1.is_do=1   then '不做了'\n" +
//                "  when t1.is_do=2   then '继续做'\n" +
//                "  when t1.is_do=3   then '补款'\n" +
//                "  when t1.is_do=4   then '退项目'\n" +
//                "  when t1.is_do=5   then '结账'\n" +
//                "  when t1.is_do=6   then '作废'\n" +
//                " end\n" +
//                "  ) isDoName,t4.recharge_people as  rechargePeople,t4.checkout_method as checkoutMethod,\n" +
//                "t3.arrival_store as arrivalStore,t1.tc_name as fieldTc,t1.check_status as checkStatus  from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id " +
//                " left join " + this.getTableName() + " t3 on t1.customer_id=t3.id " +
//                " left join " + tableName4 + " t4 on t4.id2=t1.id" +
//                " where t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "'  and t1.deal_status='已成交' " +
//                " and (t1.service_actual_pay>0 or t1.folding_pay>0) group by t1.id order by t1.get_time desc ";
//        List<PayServiceInfo> openBillList3 = sqlMapper.selectList(sql3, PayServiceInfo.class);//查询当前开单除去不做了的记录
//        Double totleReceivable = 0.00;//总的项目总价，非折后
////        Double totleServiceActualPay = 0.00;//总的实付金额（全部）
//        Double totleServiceActualPays = 0.00;//总的实付金额（除去不做的）
//        Double totleFoldingPay = 0.00;//总的折后价
//        Double accountArrears = 0.00;
//
//        for (PayServiceInfo info1 : openBillList1) {
//            if (info1 != null) {
//                if (info1.getServiceActualPay() != null) {
//                    totleServiceActualPays += info1.getServiceActualPay();
//                }
//            }
//        }
//
//        for (PayServiceInfo info : openBillList3) {
//            if (info != null) {
//                if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
//                    if (info.getPayServiceNum() != null) {
//                        totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
//                    }
//                    if (info.getFoldingPay() != null) {
//                        totleFoldingPay += info.getFoldingPay();
//                    }
//                    if (info.getArrears() != null) {
//                        accountArrears += info.getArrears();
//                    }
////                    if(!info.getOperationTime().equals(info.getGetTime())){
////                        info.setDealStatus("已成交");
////                    }
//                    info.setTotleReceivable(totleReceivable);
//                    info.setTotleFoldingPay(totleFoldingPay);
//                    info.setTotleServiceActualPay(totleServiceActualPays);
//                    info.setAccountArrears(accountArrears);
//                }
//            }
//        }
        String sql3 = "SELECT  service_actual_pay  as serviceActualPay, arrears as  arrears, " +
                " t1.id AS id,t1.customer_id AS customerId,t1.reservations_id AS reservationsId,t1.get_time AS getTime,t1.outpatient_name AS outpatientName, " +
                " t1.deal_status AS dealStatus, t1.tc_name AS tcName,t1.pay_service_num AS payServiceNum," +
                " LEFT(t1.operation_time,19) AS operationTime,t1.remarks AS remarks, t1.folding_pay AS foldingPay,t1.to_void_cause AS toVoidCause,t1.doctor AS doctor," +
                "(case \n" +
                "  when t1.is_do=1   then '不做了'\n" +
                "  when t1.is_do=2   then '继续做'\n" +
                "  when t1.is_do=3   then '补款'\n" +
                "  when t1.is_do=4   then '退项目'\n" +
                "  when t1.is_do=5   then '结账'\n" +
                "  when t1.is_do=6   then '作废'\n" +
                "  end\n" +
                "  ) isDoName," +
                " t2.department AS department,t2.first_level_project AS firstLevelProject,t2.pay_service_name AS payServiceName, t2.pay_service_price_one AS payServicePriceOne, " +
                " t2.pay_service_price_two AS payServicePriceTwo,t1.to_void_cause AS toVoidCause,t1.no_deal_cause AS noDealCause,t3.customer_name AS customerName," +
                " t3.medical_record_number AS medicalRecordNumber,t3.customer_phone AS customerPhone,t3.customer_age AS customerAge,t1.id2, " +
                " IF(t3.customer_sex='1','男','女') AS sex,t3.arrival_store AS arrivalStore,t1.tc_name AS fieldTc,t1.check_status AS checkStatus,t4.checkout_method as checkoutMethod " +
                " from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id left join " + this.getTableName() + " t3 on t1.customer_id=t3.id" +
                " left join wh_xd_recharge_info t4 on t1.reservations_id=t4.reservations_id where t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "' " +
                " and (t1.deal_status='已成交' or t1.deal_status='已开单')" +
                " GROUP BY t1.id  order by t1.get_time desc ";
        List<PayServiceInfo> openBillList3 = sqlMapper.selectList(sql3, PayServiceInfo.class);
        Double totleReceivable = 0.00;//总的项目总价，非折后
//        Double totleServiceActualPay = 0.00;//总的实付金额（全部）
        Double totleServiceActualPays = 0.00;//总的实付金额（除去不做的）
        Double totleFoldingPay = 0.00;//总的折后价
        Double accountArrears = 0.00;
        for (PayServiceInfo info : openBillList3) {
            if (info != null) {
                if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                    if (info.getPayServiceNum() != null) {
                        totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
                    }
                    if (info.getFoldingPay() != null) {
                        totleFoldingPay += info.getFoldingPay();
                    }
                    if (info.getArrears() != null) {
                        accountArrears += info.getArrears();
                    }
                    if (info.getServiceActualPay() != null) {
                        totleServiceActualPays += info.getServiceActualPay();
                    }
//                    if(!info.getOperationTime().equals(info.getGetTime())){
//                        info.setDealStatus("已成交");
//                    }
                    info.setTotleReceivable(totleReceivable);
                    info.setTotleFoldingPay(totleFoldingPay);
                    info.setTotleServiceActualPay(totleServiceActualPays);
                    info.setAccountArrears(accountArrears);
                }
            }
        }
        return openBillList3;
    }


    @RequestMapping(value = "/getOpenBillListss", method = RequestMethod.POST)
    @ResponseBody
    public List<PayServiceInfo> getOpenBillListss(String operationTime, String getTime, String customerId, String
            reservationsId) {
//        String tableHead = ShiroKit.getUser().getAbbreviation();
        operationTime = operationTime.substring(0, 10) + " " + operationTime.substring(10, operationTime.length());
//        String tableName1 = tableHead + "deal_info";
        String sql1 = "select table_name from information_schema.tables where table_schema='crms'\n" +
                "and table_name like '%customer_info%'";
        List<ReservationsInfo> list1 = sqlMapper.selectList(sql1, ReservationsInfo.class);
        String tableHead1 = list1.get(0).getTableName().substring(0, list1.get(0).getTableName().length() - 13);
        String sql = "select t1.id as id,t1.customer_id as customerId ,t1.is_do as isDo ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.doctor as doctor ,t1.left_up as leftUp ,t1.left_down as leftDown ,t1.right_up as rightUp ,t1.right_down as rightDown ,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t3.customer_name as customerName ,t3.medical_record_number as medicalRecordNumber,t3.customer_phone as customerPhone,t3.customer_age as customerAge,\n" +
                "if(t3.customer_sex='1','男','女') as sex ,t3.arrival_store as arrivalStore,t1.tc_name as fieldTc from " + tableHead1 + "deal_info t1 left join pay_service_info t2 on t1.pay_service_id=t2.id left join " + list1.get(0).getTableName() + " t3 on t1.customer_id=t3.id" +
                " where t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "' and t1.operation_time=t1.get_time";
        String sql2 = "select t1.id as id,t1.customer_id as customerId,t1.is_do as isDo  ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.doctor as doctor ,t1.left_up as leftUp ,t1.left_down as leftDown ,t1.right_up as rightUp ,t1.right_down as rightDown ,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t3.customer_name as customerName ,t3.medical_record_number as medicalRecordNumber,t3.customer_phone as customerPhone,t3.customer_age as customerAge,\n" +
                "(\n" +
                "        CASE t3.customer_sex\n" +
                "        WHEN 1 THEN\n" +
                "            '男'\n" +
                "        WHEN 2 THEN\n" +
                "            '女'\n" +
                "        ELSE\n" +
                "            '未知'\n" +
                "        END\n" +
                "    ) as sex ,t3.arrival_store as arrivalStore,t1.tc_name as fieldTc from " + tableHead1 + "deal_info t1 left join pay_service_info t2 on t1.pay_service_id=t2.id left join " + list1.get(0).getTableName() + " t3 on t1.customer_id=t3.id" +
                " where t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "' and t1.deal_status='已成交' ";
        for (int i = 1; i < list1.size(); i++) {
            tableHead1 = list1.get(i).getTableName().substring(0, list1.get(i).getTableName().length() - 13);
            sql += " union all select t1.id as id,t1.customer_id as customerId,t1.is_do as isDo  ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                    " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                    " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.doctor as doctor ,t1.left_up as leftUp ,t1.left_down as leftDown ,t1.right_up as rightUp ,t1.right_down as rightDown ,t1.pay_service as payService," +
                    "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                    "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                    "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t3.customer_name as customerName ,t3.medical_record_number as medicalRecordNumber,t3.customer_phone as customerPhone,t3.customer_age as customerAge,\n" +
                    "if(t3.customer_sex='1','男','女') as sex ,t3.arrival_store as arrivalStore,t1.tc_name as fieldTc from " + tableHead1 + "deal_info t1 left join pay_service_info t2 on t1.pay_service_id=t2.id left join " + list1.get(i).getTableName() + " t3 on t1.customer_id=t3.id" +
                    " where t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "' and t1.operation_time=t1.get_time";
            sql2 += " union all select t1.id as id,t1.customer_id as customerId ,t1.is_do as isDo ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                    " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                    " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.doctor as doctor ,t1.left_up as leftUp ,t1.left_down as leftDown ,t1.right_up as rightUp ,t1.right_down as rightDown ,t1.pay_service as payService," +
                    "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                    "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                    "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t3.customer_name as customerName ,t3.medical_record_number as medicalRecordNumber,t3.customer_phone as customerPhone,t3.customer_age as customerAge,\n" +
                    "(\n" +
                    "        CASE t3.customer_sex\n" +
                    "        WHEN 1 THEN\n" +
                    "            '男'\n" +
                    "        WHEN 2 THEN\n" +
                    "            '女'\n" +
                    "        ELSE\n" +
                    "            '未知'\n" +
                    "        END\n" +
                    "    ) as sex ,t3.arrival_store as arrivalStore,t1.tc_name as fieldTc from " + tableHead1 + "deal_info t1 left join pay_service_info t2 on t1.pay_service_id=t2.id left join " + list1.get(i).getTableName() + " t3 on t1.customer_id=t3.id" +
                    " where t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "' and t1.deal_status='已成交'";
        }
        List<PayServiceInfo> openBillList = sqlMapper.selectList(sql, PayServiceInfo.class);
        List<PayServiceInfo> openBillList2 = sqlMapper.selectList(sql2, PayServiceInfo.class);
        Double totleReceivable = 0.00;
        Double totleServiceActualPay = 0.00;
        Double totleServiceActualPays = 0.00;
        Double totleFoldingPay = 0.00;
//        Double accountArrears = 0.00;
        for (PayServiceInfo info : openBillList2) {
            if (info.getServiceActualPay() != null) {
                if (info.getIsDo() != null) {
                    if (info.getIsDo() != 1) {
                        totleServiceActualPays += info.getServiceActualPay();
                    }
                } else {
                    totleServiceActualPays += info.getServiceActualPay();
                }
            }
            if (info.getServiceActualPay() != null) {
                totleServiceActualPay += info.getServiceActualPay();
            }
        }
        for (PayServiceInfo info : openBillList) {
            if (info != null) {
                if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                    if (info.getPayServiceNum() != null) {
                        totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
                    }
                    if (info.getFoldingPay() != null) {
                        totleFoldingPay += info.getFoldingPay();
                    }
                    info.setTotleReceivable(totleReceivable);
                    info.setTotleFoldingPay(totleFoldingPay);
                    info.setTotleServiceActualPay(totleServiceActualPay);
                    info.setAccountArrears(totleFoldingPay - totleServiceActualPays);
                }
            }
        }
        return openBillList;
    }

    /**
     * 退款打印
     *
     * @param
     * @param model
     * @return
     */
    @RequestMapping(value = "/to_printt/{rcor}")
    public String printt(@PathVariable String rcor, Model model) {
        String reservationsId = rcor.split(",")[0];
        String customerId = rcor.split(",")[1];
        String operationTime = rcor.split(",")[2];
        String recordTime = rcor.split(",")[3];
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        if (ToolUtil.isEmpty(recordTime)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser
                    ().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String tableName = tableHead + "deal_info";
//        String sql = "select * from " + tableName1 + " where reservations_id='" + reservationsId + "' and record_time='" + recordTime + "'";
//        List<RefundInfo> refundInfoList = sqlMapper.selectList(sql, RefundInfo.class);
        Double refundMoney = 0.00;
        String documentNumber = "";
//        for (RefundInfo refundInfo : refundInfoList) {
//            refundMoney += refundInfo.getRefundMoney();
//            documentNumber = refundInfo.getDocumentNumber();
//        }
        String selectsql = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id" +
                " as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as " +
                "dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left (t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause from " + tableName + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id " +
                " where t1.operation_time='" + operationTime + "' " +
                "and t1.reservations_id='" + reservationsId + "'";
        List<PayServiceInfo> openBillList = sqlMapper.selectList(selectsql, PayServiceInfo.class);
        Double totleReceivable = 0.00;
        Double totleFoldingPay = 0.00;
        for (PayServiceInfo info : openBillList) {
            if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                if (info.getPayServiceNum() != null) {
                    totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
                }
                if (info.getFoldingPay() != null) {
                    totleFoldingPay += info.getFoldingPay();
                }
                info.setTotleReceivable(totleReceivable);
                info.setTotleFoldingPay(totleFoldingPay);
            }
        }
        String sql1 = "select t2.customer_name as customerName,t2.reservations_id as reservationsId,t2.medical_record_number as medicalRecordNumber," +
                "  (CASE t2.customer_sex  " +
                "  WHEN 1 THEN  " +
                "  '男'  " +
                "  WHEN 2 THEN  " +
                "  '女'  " +
                "  ELSE  " +
                "  '未知'  " +
                "  END  " +
                " ) as sex ,t2.arrival_store as outpatientName,t2.customer_age as " +
                "customerAge,t2.customer_phone as customerPhone ,t2.field_tc as tcName" +
                " from " + this.getTableName() + " t2 where id='" + customerId + "'";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        String sql22 = "select * from dept where abbreviation='" + tableHead + "'";
        Dept dept = sqlMapper.selectOne(sql22, Dept.class);

        model.addAttribute("deptInfo", dept);
        model.addAttribute("openBillList", openBillList);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("refundMoney", refundMoney);
        model.addAttribute("documentNumber", documentNumber);
        model.addAttribute("customerId", customerId);
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("operationTime", operationTime);
        model.addAttribute("recordTime", recordTime);
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        return PREFIX + "refund_print.html";
    }

    @RequestMapping(value = "/getRefundCheckoutMethod", method = RequestMethod.POST)
    @ResponseBody
    public List<RefundInfo> getRefundCheckoutMethod(String recordTime, String customerId, String reservationsId) {
//        String tableHead = ShiroKit.getUser().getAbbreviation();
//        String tableName1 = tableHead + "refund_info";
//        String sql = "select * from " + tableName1 + " where reservations_id='" + reservationsId + "' and record_time='" + recordTime + "'";
//        List<RefundInfo> refundInfoList = sqlMapper.selectList(sql, RefundInfo.class);
        List<RefundInfo> refundInfoList = new ArrayList<RefundInfo>();
        return refundInfoList;
    }

    /**
     * 退款请求的数据
     *
     * @param operationTime
     * @param customerId
     * @param reservationsId
     * @return
     */
    @RequestMapping(value = "/getTuiPrint", method = RequestMethod.POST)
    @ResponseBody
    public List<PayServiceInfo> getTuiPrint(String operationTime, String customerId,
                                            String reservationsId) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName1 = tableHead + "deal_info";
        String sql = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId " +
                ",t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName " +
                ",t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left (t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.doctor ,t1.left_Up leftUp ," +
                "t1.right_Up as rightUp,t1.left_Down as leftDown,t1.right_Down as rightDown,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as  payServicePriceOne, " +
                "t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t1.type_number as " +
                "typeNumber,t3.customer_name as customerName ,t3.medical_record_number as" +
                " medicalRecordNumber,t3.customer_phone as customerPhone,t3.customer_age as customerAge,\n" +
                "(\n" +
                "        CASE t3.customer_sex\n" +
                "        WHEN 1 THEN\n" +
                "            '男'\n" +
                "        WHEN 2 THEN\n" +
                "            '女'\n" +
                "        ELSE\n" +
                "            '未知'\n" +
                "        END\n" +
                "    ) as sex ,t3.arrival_store  as " +
                "arrivalStore,t3.field_tc as fieldTc from " + tableName1 + " t1 left join  pay_service_info t2" +
                " on t1.pay_service_id=t2.id left join " + this.getTableName() + " t3 on t1.customer_id=t3.id where t1.deal_status!='未成交' and t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "'";
        List<PayServiceInfo> openPrintList = sqlMapper.selectList(sql, PayServiceInfo.class);
        return openPrintList;
    }


    @RequestMapping(value = "/getOpenBillLists", method = RequestMethod.POST)
    @ResponseBody
    public List<PayServiceInfo> getOpenBillLists(String operationTime, String customerId, String reservationsId) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName1 = tableHead + "deal_info";
        String sql = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id " +
                " where t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "'";
        List<PayServiceInfo> openBillList = sqlMapper.selectList(sql, PayServiceInfo.class);
        String sql1 = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.doctor as doctor ,t1.left_up as leftUp ,t1.left_down as leftDown ,t1.right_up as rightUp ,t1.right_down as rightDown ,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t3.customer_name as customerName ,t3.medical_record_number as medicalRecordNumber,t3.customer_phone as customerPhone,t3.customer_age as customerAge,\n" +
                "(\n" +
                "        CASE t3.customer_sex\n" +
                "        WHEN 1 THEN\n" +
                "            '男'\n" +
                "        WHEN 2 THEN\n" +
                "            '女'\n" +
                "        ELSE\n" +
                "            '未知'\n" +
                "        END\n" +
                "    ) as sex ,t3.arrival_store as arrivalStore,t1.tc_name as fieldTc from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id left join " + this.getTableName() + " t3 on t1.customer_id=t3.id" +
                " where t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "' ";
        List<PayServiceInfo> openBillList1 = sqlMapper.selectList(sql1, PayServiceInfo.class);
        Double totleServiceActualPay = 0.00;
        for (PayServiceInfo info : openBillList1) {
            if (info != null) {
                totleServiceActualPay += info.getServiceActualPay();
                info.setTotleServiceActualPay(totleServiceActualPay);
            }
        }
        for (PayServiceInfo info : openBillList) {
            info.setTotleServiceActualPay(totleServiceActualPay);
        }
        return openBillList;
    }

    @RequestMapping(value = "/getNoDealCause", method = RequestMethod.POST)
    @ResponseBody
    public List<PayServiceInfo> getNoDealCause(String operationTime, String reservationsId) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName = tableHead + "deal_info";
        String sql = "select t.id as id , t.reservations_id as reservationsId ,t.customer_id as customerId ,t.outpatient_name\n" +
                "as outpatientName ,t.tc_name as tcName,t.pay_service_id as payServiceId,t.no_deal_cause as noDealCause,t.operation_time as operationTime," +
                "t1.department as department,t1.first_level_project as firstLevelProject" +
                " from " + tableName + " t left join pay_service_info t1 on t.pay_service_id=t1.id " +
                " where t.operation_time='" + operationTime + "' and  t.reservations_id='" + reservationsId + "'";
        List<PayServiceInfo> openBillList = sqlMapper.selectList(sql, PayServiceInfo.class);
        return openBillList;
    }

    @RequestMapping(value = "/getRevisitContent", method = RequestMethod.POST)
    @ResponseBody
    public AddVisitedInfo getRevisitContent(String revisitTime, String reservationsId) {
        String sql = "select id as id ,revisit_content as revisitContent,revisit as revisit from return_visit_info where reservations_id='" + reservationsId + "'and revisit_time='" + revisitTime + "'";
        AddVisitedInfo info = sqlMapper.selectOne(sql, AddVisitedInfo.class);
        return info;
    }

    @RequestMapping(value = "/to_print/{id}")
    public String print(@PathVariable String id, Model model) {
        if (ToolUtil.isEmpty(id)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser
                    ().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String tableName = tableHead + "deal_info";
        String sql = "select * from " + tableName + " where id='" + id + "'";
        RechargeInfo rechargeInfo = sqlMapper.selectOne(sql, RechargeInfo.class);
        String selectsql = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id" +
                " as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as " +
                "dealStatus, t1.tc_name as tcName ,t1.nurse as nurse ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left (t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause from " + tableName + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id "
                +
                " where t1.deal_status!='未成交' and  t1.operation_time='" +
                rechargeInfo.getOperationTime() + "' " +
                "and t1.reservations_id='" + rechargeInfo.getReservationsId() + "'";
        List<PayServiceInfo> openBillList = sqlMapper.selectList(selectsql,
                PayServiceInfo.class);
        Double totleReceivable = 0.00;
        Double totleFoldingPay = 0.00;
        for (PayServiceInfo info : openBillList) {
            if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                if (info.getPayServiceNum() != null) {
                    totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
                }
                if (info.getFoldingPay() != null) {
                    totleFoldingPay += info.getFoldingPay();
                }
                info.setTotleReceivable(totleReceivable);
                info.setTotleFoldingPay(totleFoldingPay);
            }
        }
        String sql1 = "select t2.customer_name as customerName,t2.reservations_id as reservationsId,t2.medical_record_number as medicalRecordNumber," +
                "  (CASE t2.customer_sex  " +
                "  WHEN 1 THEN  " +
                "  '男'  " +
                "  WHEN 2 THEN  " +
                "  '女'  " +
                "  ELSE  " +
                "  '未知'  " +
                "  END  " +
                " ) as sex ,t2.arrival_store as outpatientName,t2.customer_age as " +
                "customerAge,t2.customer_phone as customerPhone ,t2.field_tc as tcName" +
                " from " + this.getTableName() + " t2 where id='" +
                rechargeInfo.getCustomerId() + "'";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        String sql22 = "select * from dept where abbreviation='" + tableHead + "'";
        Dept dept = sqlMapper.selectOne(sql22, Dept.class);

        String sql2 = "select GROUP_CONCAT(distinct doctor) as doctor from " + tableName + " t1 " +
                "where t1.deal_status!='未成交' and t1.get_time='" + rechargeInfo.getGetTime() + "' " +
                "and t1.reservations_id='" + rechargeInfo.getReservationsId() + "'";
        PayServiceInfo payServiceInfo = sqlMapper.selectOne(sql2, PayServiceInfo.class);

        model.addAttribute("doctor", payServiceInfo.getDoctor());
        model.addAttribute("deptInfo", dept);
        model.addAttribute("openBillList", openBillList);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("rechargeInfo", rechargeInfo);
        model.addAttribute("reservationsId", rechargeInfo.getReservationsId());
        model.addAttribute("customerId", rechargeInfo.getCustomerId());
        model.addAttribute("operationTime", rechargeInfo.getOperationTime());
        model.addAttribute("getTime", rechargeInfo.getGetTime());
        model.addAttribute("reservationsId", rechargeInfo.getReservationsId());
        model.addAttribute("userName", ShiroKit.getUser().getAccount());

        String deletesql = "delete from temporary_recharge_info where reservations_id='" + rechargeInfo.getReservationsId() + "'" +
                " and operation_time='" + rechargeInfo.getGetTime() + "'";
        sqlMapper.delete(deletesql);

        String tableName1 = tableHead + "recharge_info";
        String sql4 = "select sum(actual_account_balance) as actualAccountBalance,a.checkout_method as  checkoutMethod from " + tableName1 + " a" +
                " where reservations_id='" + rechargeInfo.getReservationsId()
                + "' and operation_time='" + rechargeInfo.getGetTime() + "' group by checkout_method ;";
        List<RechargeInfo> openCheckoutMethodInfoList = sqlMapper.selectList(sql4, RechargeInfo.class);
        model.addAttribute("openCheckoutMethodInfoList", openCheckoutMethodInfoList);

        String sql5 = "select GROUP_CONCAT(remarks) as remarks from " + tableName1 + " a" +
                " where reservations_id='" + rechargeInfo.getReservationsId()
                + "' and operation_time='" + rechargeInfo.getGetTime() + "' ";
        RechargeInfo remarksList = sqlMapper.selectOne(sql5, RechargeInfo.class);
        model.addAttribute("remarksList", remarksList);

        return PREFIX + "print.html";
    }

    @RequestMapping(value = "/getOpenPrint", method = RequestMethod.POST)
    @ResponseBody
    public List<PayServiceInfo> getOpenPrint(String operationTime, String customerId, String getTime, String
            reservationsId) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName1 = tableHead + "deal_info";
        String sql = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId " +
                ",t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName " +
                ",t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left (t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.doctor ,t1.left_Up leftUp ," +
                "t1.right_Up as rightUp,t1.left_Down as leftDown,t1.right_Down as rightDown,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.unit as unit,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as  payServicePriceOne, " +
                "t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t1.type_number as " +
                "typeNumber,t3.customer_name as customerName ,t3.medical_record_number as" +
                " medicalRecordNumber,t3.customer_phone as customerPhone,t3.customer_age as customerAge,\n" +
                "(\n" +
                "        CASE t3.customer_sex\n" +
                "        WHEN 1 THEN\n" +
                "            '男'\n" +
                "        WHEN 2 THEN\n" +
                "            '女'\n" +
                "        ELSE\n" +
                "            '未知'\n" +
                "        END\n" +
                "    ) as sex ,t3.arrival_store  as " +
                "arrivalStore,t3.field_tc as fieldTc from " + tableName1 + " t1 left join  pay_service_info t2" +
                " on t1.pay_service_id=t2.id left join " + this.getTableName() + " t3 on t1.customer_id=t3.id where t1.deal_status!='未成交'" +
                " and t1.operation_time='" + operationTime + "' and t1.reservations_id='" + reservationsId + "' and t1.operation_time=t1.get_time";
        String sql1 = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId " +
                ",t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName " +
                ",t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left (t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.doctor ,t1.left_Up leftUp ," +
                "t1.right_Up as rightUp,t1.left_Down as leftDown,t1.right_Down as rightDown,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "t2.pay_service_name as payServiceName,t2.unit as unit, t2.pay_service_price_one as  payServicePriceOne, " +
                "t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t1.type_number as " +
                "typeNumber,t3.customer_name as customerName ,t3.medical_record_number as" +
                " medicalRecordNumber,t3.customer_phone as customerPhone,t3.customer_age as customerAge,\n" +
                "(\n" +
                "        CASE t3.customer_sex\n" +
                "        WHEN 1 THEN\n" +
                "            '男'\n" +
                "        WHEN 2 THEN\n" +
                "            '女'\n" +
                "        ELSE\n" +
                "            '未知'\n" +
                "        END\n" +
                "    ) as sex ,t3.arrival_store  as " +
                "arrivalStore,t3.field_tc as fieldTc from " + tableName1 + " t1 left join  pay_service_info t2" +
                " on t1.pay_service_id=t2.id left join " + this.getTableName() + " t3 on t1.customer_id=t3.id where t1.deal_status!='未成交' " +
                "and t1.get_time='" + getTime + "' and t1.reservations_id='" + reservationsId + "'";
        List<PayServiceInfo> openPrintList = sqlMapper.selectList(sql, PayServiceInfo.class);
        List<PayServiceInfo> openPrintList1 = sqlMapper.selectList(sql1, PayServiceInfo.class);
        Double totleReceivable = 0.00;
        Double totleServiceActualPay = 0.00;
        Double totleFoldingPay = 0.00;
        Double accountArrears = 0.00;
        Double scArrears = 0.00;   //上次欠费

        if (!operationTime.equals(getTime)) {
            String sql3 = "select sum(t.arrears) scarrears from (select * from " + tableName1 + " t1 " +
                    "where t1.deal_status!='未成交' and t1.get_time < '" + getTime + "'and t1.reservations_id='" + reservationsId + "'  " +
                    " order by t1.get_time desc  limit 0," + openPrintList1.size() + ") t";
            PayServiceInfo arrears = sqlMapper.selectOne(sql3, PayServiceInfo.class);
            scArrears = arrears.getScarrears();

            for (PayServiceInfo info : openPrintList1) {
                if (info != null) {
                    if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                        if (info.getServiceActualPay() != null) {
                            totleServiceActualPay += info.getServiceActualPay();
                        }
                        if (info.getArrears() != null) {
                            accountArrears += info.getArrears();
                        }
                    }
                }
            }
            for (PayServiceInfo info : openPrintList) {
                if (info != null) {
                    if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                        if (info.getPayServiceNum() != null) {
                            totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
                        }
                        if (info.getFoldingPay() != null) {
                            totleFoldingPay += info.getFoldingPay();
                        }
                        if (info.getServiceActualPay() != null) {
                            totleServiceActualPay += info.getServiceActualPay();
                        }
                    }
                }
                info.setTotleReceivable(totleReceivable);
                info.setTotleFoldingPay(totleFoldingPay);
                info.setTotleServiceActualPay(totleServiceActualPay);
                info.setAccountArrears(accountArrears);
                info.setScarrears(scArrears);
            }
        } else {
            for (PayServiceInfo info : openPrintList) {
                if (info != null) {
                    if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                        if (info.getPayServiceNum() != null) {
                            totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
                        }
                        if (info.getFoldingPay() != null) {
                            totleFoldingPay += info.getFoldingPay();
                        }
                        if (info.getServiceActualPay() != null) {
                            totleServiceActualPay += info.getServiceActualPay();
                        }
                        if (info.getArrears() != null) {
                            accountArrears += info.getArrears();
                        }
                    }
                }
                info.setTotleReceivable(totleReceivable);
                info.setTotleFoldingPay(totleFoldingPay);
                info.setTotleServiceActualPay(totleServiceActualPay);
                info.setAccountArrears(accountArrears);
                info.setScarrears(scArrears);
            }
        }
        return openPrintList;
    }

    @RequestMapping(value = "/getCheckoutMethod", method = RequestMethod.POST)
    @ResponseBody
    public List<RechargeInfo> getCheckoutMethod(String operationTime, String
            customerId, String reservationsId, String getTime) {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName1 = tableHead + "recharge_info";
        String sql = "select * from " + tableName1 + " where reservations_id='" + reservationsId + "' and operation_time='" + getTime + "';";
        List<RechargeInfo> openCheckoutMethodInfoList = sqlMapper.selectList(sql, RechargeInfo.class);
        return openCheckoutMethodInfoList;
    }

    /**
     * 添加预约回访记录
     */
    @RequestMapping(value = "/to_revisitRecord/{reservationsId}")
    public String appointment(Model model, @PathVariable String reservationsId) throws Exception {
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        List<AddVisitedInfo> revisitRecordList = service.getRevisitRecordList(reservationsId);
        String sql = "select t2.customer_name as customerName, t2.customer_phone as customerPhone,t2.reservations_id as reservationsId,t2.medical_record_number as medicalRecordNumber," +
                "  (CASE t2.customer_sex  " +
                "  WHEN 1 THEN  " +
                "  '男'  " +
                "  WHEN 2 THEN  " +
                "  '女'  " +
                "  ELSE  " +
                "  '未知'  " +
                "  END  " +
                " ) as sex ,t2.customer_age as customerAge ,t2.field_tc as tcName" +
                " from " + this.getTableName() + " t2 where reservations_id='" + reservationsId + "' order by t2.arrival_time desc limit 0,1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql, ConsultantInfo.class);
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("revisitRecordList", revisitRecordList);
        model.addAttribute("reservationsId", reservationsId);
        return PREFIX + "revisitRecord.html";
    }

    @RequestMapping(value = "/add_isNoDeal")
    @ResponseBody
    public int add_isNoDeal(@Valid DealInfo info, BindingResult result) throws Exception {
        if (result.hasErrors()) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String appointmentTime = "";
        if (info.getAppointmentTimes() == null || info.getAppointmentTimes() == "") {
            appointmentTime = "null";
        } else {
            appointmentTime = "'" + info.getAppointmentTimes() + "'";
        }
        info.setOutpatientName(ShiroKit.getSessionAttr("outpatientName"));
        String updateSql = "update " + this.getTableName() + " set deal_status='未成交',diagnosis_status='已看诊' where id='" + info.getCustomerId() + "'  ";
        sqlMapper.update(updateSql);
        service.updateDeal(info);
        String sql = "update " + this.getTableName() + " set is_return_visit=" + info.getIsReturnVisit() + ",follow_status='" + info.getFollowStatuss() + "',consumption_status='" + info.getConsumptionStatuss() + "'," +
                " reservations='" + info.getReservationss() + "',appointment_time=" + appointmentTime + " " +
                " where reservations_id='" + info.getReservationsId() + "'";
        sqlMapper.update(sql);
        return service.insertNoDeal(info);
    }

    @RequestMapping(value = "/add_isToVoid")
    @ResponseBody
    public int add_isToVoid(@Valid DealInfo info, BindingResult result) throws Exception {
        if (result.hasErrors()) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName1 = tableHead + "deal_info";
        info.setOutpatientName(ShiroKit.getSessionAttr("outpatientName"));
        String selectsql = "select * from " + this.getTableName() + " where id='" + info.getCustomerId() + "' limit 0,1";
        CustomerInfo customerInfo = sqlMapper.selectOne(selectsql, CustomerInfo.class);
        if (customerInfo != null) {
            if (!"已成交".equals(customerInfo.getDealStatus())) {
                String updateSql = "update " + this.getTableName() + " set deal_status='作废' where id='" + info.getCustomerId() + "'  ";
                sqlMapper.update(updateSql);
            }
        }
        String sql = "update " + tableName1 + " a set a.deal_status='作废',a.to_void_cause='" + info.getToVoidCause() + "' where a.reservations_id='" + info.getReservationsId() + "' and a.operation_time='" + info.getOperationTime() + "'" +
                "and a.outpatient_name='" + info.getOutpatientName() + "' ";
        return sqlMapper.update(sql);
    }

    @RequestMapping(value = "/openBillList/{customerId}")
    public String openBillList(@PathVariable String customerId, Model model) throws Exception {
        if (ToolUtil.isEmpty(customerId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        model.addAttribute("customerId", customerId);
        ConsultantInfo consultantInfo = service.selectOneById(customerId);
        model.addAttribute("reservationsId", consultantInfo.getReservationsId());
        return PREFIX + "openBillList.html";
    }

    @RequestMapping(value = "/to_openNoOperation/{ids}")
    public String to_openNoOperation(@PathVariable String ids, Model model) throws Exception {
        String reservationsId = ids.split(",")[0];
        String customerId = ids.split(",")[1];
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String tableName1 = tableHead + "deal_info";
        String sql = "select id as id , reservations_id as reservationsId ,customer_id as customerId ,outpatient_name\n" +
                "as outpatientName ,tc_name as tcName,pay_service_id as payServiceId, " +
                " no_deal_cause as noDealCause,left(operation_time,19) as operationTime from " + tableName1 + " where reservations_id='" + reservationsId + "' and deal_status='未成交' order by  operation_time desc";
        List<PayServiceInfo> payServiceInfoList = sqlMapper.selectList(sql, PayServiceInfo.class);
        String sql1 = "select t2.customer_name as customerName,t2.reservations_id as reservationsId,t2.medical_record_number as medicalRecordNumber," +
                "  (CASE t2.customer_sex  " +
                "  WHEN 1 THEN  " +
                "  '男'  " +
                "  WHEN 2 THEN  " +
                "  '女'  " +
                "  ELSE  " +
                "  '未知'  " +
                "  END  " +
                " ) as sex ,t2.customer_age as customerAge,t2.customer_phone as customerPhone ,t2.field_tc as tcName" +
                " from " + this.getTableName() + " t2 where reservations_id='" + reservationsId + "' order by arrival_time desc limit 0,1";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        if (payServiceInfoList.size() > 0) {
            consultantInfo.setTcName(payServiceInfoList.get(0).getTcName());
        }
        model.addAttribute("payServiceInfoList", payServiceInfoList);
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("customerId", customerId);
        model.addAttribute("consultantInfo", consultantInfo);
        return PREFIX + "noOperationRecord.html";
    }

    @RequestMapping(value = "/openBill")
    @ResponseBody
    public int openBill(@Valid PaymentInfo info, Model model) throws Exception {
        model.addAttribute("customerId", info.getCustomerId());
        try {
            String selectsql = "select * from " + this.getTableName() + " where id='" + info.getCustomerId() + "' limit 0,1";
            CustomerInfo customerInfo = sqlMapper.selectOne(selectsql, CustomerInfo.class);
            if (customerInfo != null) {
                if (!"已成交".equals(customerInfo.getDealStatus())) {
                    String sql = "update " + this.getTableName() + " set deal_status='已开单' where id='" + info.getCustomerId() + "'";
                    sqlMapper.update(sql);
                }
            }
            return service.insertDeal(info);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 1;
    }


    @RequestMapping(value = "/addVisited")
    @ResponseBody
    public int addVisited(@Valid CustomerInfo info, BindingResult result) throws Exception {
        if (result.hasErrors()) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        service.updateIsReturnVisit(info);
        return service.insertReturnVisit(info);
    }


    @RequestMapping(value = "/to_openBileLists/{id}")
    public String to_openBileLists(@PathVariable String id, Model model) throws Exception {
        if (ToolUtil.isEmpty(id)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        CustomerInfo customerInfo = customerService.selectOneById(id);
        String sqlresrvations = "select * from reservations_info where id='" + customerInfo.getReservationsId() + "' limit 0,1";
        ReservationsInfo reservationsInfo = sqlMapper.selectOne(sqlresrvations, ReservationsInfo.class);
        if (reservationsInfo == null) {
            String sqlcu = "select * from " + this.getTableName() + "  where id='" + id + "'";
            CustomerInfo customer = sqlMapper.selectOne(sqlcu, CustomerInfo.class);
            reservationsService.insert(customer);
//            String sqlresrvations1 = "select * from reservations_info where id='" + customerInfo.getReservationsId() + "' limit 0,1";
//            reservationsInfo = sqlMapper.selectOne(sqlresrvations1, ReservationsInfo.class);
        }
        //看诊详情
        List<ConsultantInfo> consultantInfoList = service.getConsultantInfoList(customerInfo.getReservationsId());
//        String tcName = "";
//        String firstVisitDate = "";
//        if (customerInfo != null) {
//            tcName = customerInfo.getFieldTc();
//            firstVisitDate = customerInfo.getFirstVisitDate();
//        }
        for (ConsultantInfo info1 : consultantInfoList) {
            if (info1.getDiagnosisTime() != "" && info1.getDiagnosisTime() != null) {
                info1.setDiagnosisTimeOne(info1.getDiagnosisTime().substring(0, 10));
                info1.setDiagnosisTimeTwo(info1.getDiagnosisTime().substring(11, info1.getDiagnosisTime().length()));
            }
        }
        //就诊记录
        String sql11 = "select left(t.create_appointment_time,19) as createAppointmentTime,left(t.start_time,19) as startTime,t.id as id,t.reservations_id as reservationsId,t.doctor as doctor,t.field_tc as fieldTc,t.remarks as remarks," +
                "t.archiving as archiving,t.arrival_store as arrivalStore,t.customer_status as customerStatus,t.status as status from " + this.getTableName() + " t where t.reservations_id='" + customerInfo.getReservationsId() + "' order by start_time desc";
        List<CustomerInfo> customerInfoList = sqlMapper.selectList(sql11, CustomerInfo.class);
        for (CustomerInfo infos : customerInfoList) {
            if (infos.getStartTime() != "" && infos.getStartTime() != null) {
                infos.setStartTimeOne(infos.getStartTime().substring(0, 10));
                infos.setStartTimeTwo(infos.getStartTime().substring(11, infos.getStartTime().length()));
            }
        }

        //成交记录
        String tableName1 = tableHead + "deal_info";
        String sql = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime," +
                "sum(t1.service_actual_pay) as totleServiceActualPay,sum(t1.folding_pay) as totleFoldingPay," +
                "sum(t1.arrears) as totleArrears,group_concat(distinct t1.remarks) as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "group_concat(distinct t2.pay_service_name) as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t1.get_time as getTime ," +
                " group_concat(distinct t1.doctor) as doctor" +
                " from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id " +
                " where t1.reservations_id='" + customerInfo.getReservationsId() + "' and pay_service_id is not null and t1.deal_status='已成交' group by  operationTime order by operationTime desc";
        List<PayServiceInfo> payServiceInfoList = sqlMapper.selectList(sql, PayServiceInfo.class);
        String sql2 = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t1.get_time as getTime, " +
                "group_concat(distinct t1.doctor) as doctor from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id " +
                " where t1.reservations_id='" + customerInfo.getReservationsId() + "' and pay_service_id is not null and t1.operation_time=t1.get_time group by  operationTime order by operationTime desc";
        List<PayServiceInfo> payServiceInfoList1 = sqlMapper.selectList(sql2, PayServiceInfo.class);
        String sql1 = "select t2.id as id,t2.customer_name as customerName,t2.reservations_id as reservationsId,t2.medical_record_number as medicalRecordNumber," +
                "  (CASE t2.customer_sex  " +
                "  WHEN 1 THEN  " +
                "  '男'  " +
                "  WHEN 2 THEN  " +
                "  '女'  " +
                "  ELSE  " +
                "  '未知'  " +
                "  END  " +
                " ) as sex ,t2.customer_age as customerAge,t2.customer_phone as customerPhone ,t2.field_tc as fieldTc" +
                " from " + this.getTableName() + " t2 where id='" + id + "'";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        String getTime = "";
        /*Double totleReceivable = 0.00;
        Double totleFoldingPay = 0.00;
        Double totleServiceActualPay = 0.00;
        Double accountArrears = 0.00;
        for (PayServiceInfo info1 : payServiceInfoList1) {
            if (info1 != null) {
                if (info1.getPayServiceId() != null && info1.getPayServiceId() != "") {
                    if (info1.getPayServiceNum() != null) {
                        totleReceivable += (info1.getPayServicePriceTwo()) * (info1.getPayServiceNum());
                    }
                    if (info1.getFoldingPay() != null) {
                        totleFoldingPay += info1.getFoldingPay();
                    }
                    info1.setTotleReceivable(totleReceivable);
                    info1.setTotleFoldingPay(totleFoldingPay);
                }
            }
        }*/
        for (PayServiceInfo info : payServiceInfoList) {
            if (info != null) {
              /*   if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                    if (info.getServiceActualPay() != null) {
                        totleServiceActualPay += info.getServiceActualPay();
                    }
                    if (info.getArrears() != null) {
                        accountArrears += info.getArrears();
                    }
                    info.setTotleReceivable(totleReceivable);
                    info.setTotleFoldingPay(totleFoldingPay);
                    info.setTotleServiceActualPay(totleServiceActualPay);
                    info.setAccountArrears(totleServiceActualPay - totleServiceActualPay);
                }*/
                if (info.getOperationTime() != "" && info.getOperationTime() != null) {
                    info.setOperationTimeOne(info.getOperationTime().substring(0, 10));
                    info.setOperationTimeTwo(info.getOperationTime().substring(11, info.getOperationTime().length()));
                }
                getTime = info.getGetTime();
            }
        }
        String selectrolesql = "select b.name as name from user a left join role b on a.roleid=b.id where a.account='" + ShiroKit.getUser().getAccount() + "'";
        Role role = sqlMapper.selectOne(selectrolesql, Role.class);
        model.addAttribute("roleName", role.getName());
        model.addAttribute("payServiceInfoList", payServiceInfoList);
        model.addAttribute("reservationsId", customerInfo.getReservationsId());
        model.addAttribute("customerId", id);
        model.addAttribute("customerInfo", customerInfo);
        model.addAttribute("getTime", getTime);
        model.addAttribute("consultantInfo", consultantInfo);
        model.addAttribute("consultantInfoList", consultantInfoList);
        model.addAttribute("customerInfoList", customerInfoList);//就诊记录
        return PREFIX + "customer_customerDetails.html";
    }

    @RequestMapping(value = "/to_openBileListss/{reservationsId}")
    public String to_openBileListss(@PathVariable String reservationsId, Model model) throws Exception {
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String sql1 = "select table_name from information_schema.tables where table_schema='crms'\n" +
                "and table_name like '%customer_info%'";
        List<ReservationsInfo> list1 = sqlMapper.selectList(sql1, ReservationsInfo.class);
        String tableHead1 = list1.get(0).getTableName().substring(0, list1.get(0).getTableName().length() - 13);
        String sql = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ," +
                "t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ," +
                "t1.pay_service_num as payServiceNum , t1.service_actual_pay as serviceActualPay ," +
                "left(t1.operation_time,19) as operationTime,t1.remarks as remarks, t1.folding_pay as foldingPay," +
                "t1.to_void_cause as toVoidCause,t1.pay_service as payService,t2.id as payServiceId," +
                "t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, " +
                "t2.pay_service_price_two as payServicePriceTwo,t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,\n" +
                "t3.customer_name as customerName,t3.reservations_id as reservationsId,t3.medical_record_number as medicalRecordNumber," +
                "t3.customer_sex as customerSex,t3.customer_age as customerAge,t3.customer_phone as customerPhone ,t3.field_tc as fieldTc \n" +
                " ,t1.get_time as getTime from " + tableHead1 + "deal_info t1 left join pay_service_info t2 on t1.pay_service_id=t2.id left join " + list1.get(0).getTableName() + " t3 on t1.customer_id=t3.id\n" +
                " where t1.reservations_id='" + reservationsId + "' and pay_service_id is not null  " +
                " group by  operationTime ";
        for (int i = 1; i < list1.size(); i++) {
            tableHead1 = list1.get(i).getTableName().substring(0, list1.get(i).getTableName().length() - 13);
            sql += " union all select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ," +
                    "t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ," +
                    "t1.pay_service_num as payServiceNum , t1.service_actual_pay as serviceActualPay ," +
                    "left(t1.operation_time,19) as operationTime,t1.remarks as remarks, t1.folding_pay as foldingPay," +
                    "t1.to_void_cause as toVoidCause,t1.pay_service as payService,t2.id as payServiceId," +
                    "t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                    "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, " +
                    "t2.pay_service_price_two as payServicePriceTwo,t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,\n" +
                    "t3.customer_name as customerName,t3.reservations_id as reservationsId,t3.medical_record_number as medicalRecordNumber," +
                    "  (CASE t3.customer_sex  " +
                    "  WHEN 1 THEN  " +
                    "  '男'  " +
                    "  WHEN 2 THEN  " +
                    "  '女'  " +
                    "  ELSE  " +
                    "  '未知'  " +
                    "  END  " +
                    " ) as sex ,t3.customer_age as customerAge,t3.customer_phone as customerPhone ,t3.field_tc as fieldTc \n" +
                    " ,t1.get_time as getTime from " + tableHead1 + "deal_info t1 left join pay_service_info t2 on t1.pay_service_id=t2.id left join " + list1.get(i).getTableName() + " t3 on t1.customer_id=t3.id\n" +
                    " where t1.reservations_id='" + reservationsId + "' and pay_service_id is not null  " +
                    " group by  operationTime ";
        }
        sql += " order by operationTime desc";
        List<PayServiceInfo> payServiceInfoList = sqlMapper.selectList(sql, PayServiceInfo.class);
        Double totleReceivable = 0.00;
        Double totleFoldingPay = 0.00;
        Double totleServiceActualPay = 0.00;
        Double accountArrears = 0.00;
        String getTime = "";
        for (PayServiceInfo info : payServiceInfoList) {
            if (info != null) {
                if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                    if (info.getPayServiceNum() != null) {
                        totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
                    }
                    if (info.getFoldingPay() != null) {
                        totleFoldingPay += info.getFoldingPay();
                    }
                    if (info.getServiceActualPay() != null) {
                        totleServiceActualPay += info.getServiceActualPay();
                    }
                    if (info.getArrears() != null) {
                        accountArrears += info.getArrears();
                    }
                    info.setTotleReceivable(totleReceivable);
                    info.setTotleFoldingPay(totleFoldingPay);
                    info.setTotleServiceActualPay(totleServiceActualPay);
                    info.setAccountArrears(accountArrears);
                }
                getTime = info.getGetTime();
            }
        }
        model.addAttribute("payServiceInfoList", payServiceInfoList);
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("getTime", getTime);
        return PREFIX + "openBillListss.html";
    }

    @RequestMapping(value = "/to_openBileList/{ids}")
    public String to_openBileList(@PathVariable String ids, Model model) throws Exception {
        String reservationsId = ids.split(",")[0];
        String customerId = ids.split(",")[1];
        if (ToolUtil.isEmpty(reservationsId)) {
            throw new BussinessException(BizExceptionEnum.REQUEST_NULL);
        }
        String tableHead = ShiroKit.getUser().getAbbreviation();
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        String tableName1 = tableHead + "deal_info";
        String sql = "select t1.id as id,t1.customer_id as customerId ,t1.reservations_id as reservationsId ,t1.outpatient_name as outpatientName , t1.deal_status  as dealStatus, t1.tc_name as tcName ,t1.pay_service_num as payServiceNum ," +
                " t1.service_actual_pay as serviceActualPay ,left(t1.operation_time,19) as operationTime,t1.remarks as remarks," +
                " t1.folding_pay as foldingPay,t1.to_void_cause as toVoidCause,t1.pay_service as payService," +
                "t2.id as payServiceId,t2.department as department,t2.first_level_project as firstLevelProject,t1.arrears as arrears," +
                "t2.pay_service_name as payServiceName, t2.pay_service_price_one as payServicePriceOne, t2.pay_service_price_two as payServicePriceTwo," +
                "t1.to_void_cause as toVoidCause ,t1.no_deal_cause as noDealCause,t1.get_time as getTime from " + tableName1 + " t1 left join pay_service_info t2 on t1.pay_service_id=t2.id " +
                " where t1.reservations_id='" + reservationsId + "' and pay_service_id is not null  group by  operationTime order by operationTime desc";
        List<PayServiceInfo> payServiceInfoList = sqlMapper.selectList(sql, PayServiceInfo.class);
        String sql1 = "select t2.customer_name as customerName,t2.reservations_id as reservationsId,t2.medical_record_number as medicalRecordNumber," +
                "  (CASE t2.customer_sex  " +
                "  WHEN 1 THEN  " +
                "  '男'  " +
                "  WHEN 2 THEN  " +
                "  '女'  " +
                "  ELSE  " +
                "  '未知'  " +
                "  END  " +
                " ) as sex ,t2.customer_age as customerAge,t2.customer_phone as customerPhone ,t2.field_tc as fieldTc" +
                " from " + this.getTableName() + " t2 where id='" + customerId + "'";
        ConsultantInfo consultantInfo = sqlMapper.selectOne(sql1, ConsultantInfo.class);
        String getTime = "";
        if (consultantInfo != null) {
            if (consultantInfo.getTcName() == "" || consultantInfo.getTcName() == null) {
                consultantInfo.setTcName(ShiroKit.getUser().getAccount());
            }
        }
        Double totleReceivable = 0.00;
        Double totleFoldingPay = 0.00;
        Double totleServiceActualPay = 0.00;
        Double accountArrears = 0.00;
        for (PayServiceInfo info : payServiceInfoList) {
            if (info != null) {
                if (info.getPayServiceId() != null && info.getPayServiceId() != "") {
                    if (info.getPayServiceNum() != null) {
                        totleReceivable += (info.getPayServicePriceTwo()) * (info.getPayServiceNum());
                    }
                    if (info.getFoldingPay() != null) {
                        totleFoldingPay += info.getFoldingPay();
                    }
                    if (info.getServiceActualPay() != null) {
                        totleServiceActualPay += info.getServiceActualPay();
                    }
                    if (info.getArrears() != null) {
                        accountArrears += info.getArrears();
                    }
                    info.setTotleReceivable(totleReceivable);
                    info.setTotleFoldingPay(totleFoldingPay);
                    info.setTotleServiceActualPay(totleServiceActualPay);
                    info.setAccountArrears(accountArrears);
                }
                getTime = info.getGetTime();
            }
        }
        model.addAttribute("payServiceInfoList", payServiceInfoList);
        model.addAttribute("reservationsId", reservationsId);
        model.addAttribute("customerId", customerId);
        model.addAttribute("getTime", getTime);
        model.addAttribute("consultantInfo", consultantInfo);
        return PREFIX + "openBillList.html";
    }

    @RequestMapping(value = "/consultantExport")
    public void reservationsExport(@RequestParam(required = false) String startArrivalTime,
                                   @RequestParam(required = false) String endArrivalTime,
                                   @RequestParam(required = false) String reach,
                                   @RequestParam(required = false) String fieldTc,
                                   @RequestParam(required = false) String dealStatus,
                                   @RequestParam(required = false) String consumptionStatus,
                                   @RequestParam(required = false) String followStatus, HttpServletResponse response) {
        try {
            SearchCustomerInfo searchInfo = new SearchCustomerInfo();
            searchInfo.setReach(reach);
            searchInfo.setConsumptionStatus(consumptionStatus);
            searchInfo.setFollowStatus(followStatus);
            searchInfo.setDealStatus(dealStatus);
            searchInfo.setStartArrivalTime(startArrivalTime);
            searchInfo.setEndArrivalTime(endArrivalTime);
            searchInfo.setFieldTc(fieldTc);
            List<CustomerInfo> list = service.consultantExportt(searchInfo);
            // 解析成excel文件
            // 第一步，创建一个webbook，对应一个Excel文件
            HSSFWorkbook wb = new HSSFWorkbook();
            // 第二步，在wb中添加一个sheet,对应Excel文件中的sheet
            HSSFSheet sheet = wb.createSheet("前端导出");
            for (int i = 0; i < 19; i++) {
                sheet.setColumnWidth(i, 24 * 256);
            }
            // 第三步，在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
            HSSFRow row = sheet.createRow(0);
            // 第四步，创建单元格，并设置值表头 设置表头居中
            HSSFCellStyle style = wb.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER);// 创建一个居中格式
            HSSFCell cell = row.createCell(0);
            cell.setCellValue("客户状态");
            cell.setCellStyle(style);
            cell = row.createCell(1);
            cell.setCellValue("病历号");
            cell.setCellStyle(style);
            cell = row.createCell(2);
            cell.setCellValue("姓名");
            cell.setCellStyle(style);
            cell = row.createCell(3);
            cell.setCellValue("性别");
            cell.setCellStyle(style);
            cell = row.createCell(4);
            cell.setCellValue("年龄");
            cell.setCellStyle(style);
            cell = row.createCell(5);
            cell.setCellValue("手机号");
            cell.setCellStyle(style);
            cell = row.createCell(6);
            cell.setCellValue("咨询项目");
            cell.setCellStyle(style);
            cell = row.createCell(7);
            cell.setCellValue("一级渠道");
            cell.setCellStyle(style);
            cell = row.createCell(8);
            cell.setCellValue("二级渠道");
            cell.setCellStyle(style);
            cell = row.createCell(9);
            cell.setCellValue("三级渠道");
            cell.setCellStyle(style);
            cell = row.createCell(10);
            cell.setCellValue("首次到店时间");
            cell.setCellStyle(style);
            cell = row.createCell(11);
            cell.setCellValue("到店时间");
            cell.setCellStyle(style);
            cell = row.createCell(12);
            cell.setCellValue("tc");
            cell.setCellStyle(style);
            cell = row.createCell(13);
            cell.setCellValue("成交状态");
            cell.setCellStyle(style);
            cell = row.createCell(14);
            cell.setCellValue("成交金额");
            cell.setCellStyle(style);
            cell = row.createCell(15);
            cell.setCellValue("欠费金额");
            cell.setCellStyle(style);
            // 填充数据
            for (int i = 0; i < list.size(); i++) {
                CustomerInfo map = list.get(i);
                row = sheet.createRow(i + 1);
                int customerAge = 0;
                if (map.getCustomerAge() != null) {
                    customerAge = map.getCustomerAge();
                }
                String medicalRecordNumber = map.getMedicalRecordNumber();
                String appointmentPayService = map.getAppointmentPayService();
                String arrivalTime = map.getArrivalTime();
                String customerStatus = "";
                if (map.getCustomerStatus() != null && map.getCustomerStatus() != "") {
                    customerStatus = map.getCustomerStatus();
                }
                String xcustomerStatus = "";
                if (map.getXcustomerStatus() != null && map.getXcustomerStatus() != "") {
                    xcustomerStatus = map.getXcustomerStatus();
                }
                String customerPhone = "";
                if (map.getCustomerPhone() != null && map.getCustomerPhone() != "") {
                    customerPhone = map.getCustomerPhone();
                }
                String customerName = "";
                if (map.getCustomerName() != null && map.getCustomerName() != "") {
                    customerName = map.getCustomerName();
                }
                String sex = "";
                if (map.getSex() != null) {
                    sex = map.getSex();
                }
                fieldTc = "";
                if (map.getFieldTc() != null && map.getFieldTc() != "") {
                    fieldTc = map.getFieldTc();
                }
                String oneChannel = map.getOneChannel();
                String twoChannel = map.getTwoChannel();
                String thrChannel = map.getThrChannel();
                String firstVisitDate = map.getFirstVisitDate();
                if (map.getDealStatus() != null && map.getDealStatus() != "") {
                    dealStatus = map.getDealStatus();
                }
                String actualAccountBalances = map.getActualAccountBalances();
                if (StringUtil.isEmpty(actualAccountBalances)) {
                    actualAccountBalances = "0.00";
                }
                String accountArrearss = map.getAccountArrearss();
                if (StringUtil.isEmpty(accountArrearss)) {
                    accountArrearss = "0.00";
                }
                String id = map.getId();
                // 第四步，创建单元格，并设置值
                for (int j = 0; j <= 15; j++) {
                    row.createCell(j).setCellStyle(style);
                }
                // row.getCell(0).setCellValue(customerStatus);
                row.getCell(0).setCellValue(xcustomerStatus);
                row.getCell(1).setCellValue(medicalRecordNumber);
                row.getCell(2).setCellValue(customerName);
                row.getCell(3).setCellValue(sex);
                row.getCell(4).setCellValue(customerAge);
                row.getCell(5).setCellValue(customerPhone);
                row.getCell(6).setCellValue(appointmentPayService);
                row.getCell(7).setCellValue(oneChannel);
                row.getCell(8).setCellValue(twoChannel);
                row.getCell(9).setCellValue(thrChannel);
                row.getCell(10).setCellValue(firstVisitDate);
                row.getCell(11).setCellValue(arrivalTime);
                row.getCell(12).setCellValue(fieldTc);
                row.getCell(13).setCellValue(dealStatus);
                row.getCell(14).setCellValue(actualAccountBalances);
                row.getCell(15).setCellValue(accountArrearss);
            }
            String date = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new java.util.Date());
            String filename = "data" + date + ".xls";
            response.setHeader("Content-Disposition",
                    "attachment; filename=\"" + URLEncoder.encode(filename, "UTF-8") + "\"");
            response.setContentType("application/octet-stream;charset=UTF-8");
            OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
            wb.write(outputStream);
            outputStream.flush();
            outputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public String getTableName() {
        String tableHead = ShiroKit.getUser().getAbbreviation();
        String tableName = tableHead + "customer_info";
        if (tableHead == "" || tableHead == null) {
            LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
            ShiroKit.getSubject().logout();
            return "/login.html";
        }
        return tableName;
    }

}
